12112022-03-25 19:30:41Szin AttilaPletykacpp14Runtime error 0/1004ms2132 KiB
#include <bits/stdc++.h>
using namespace std;
#define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using ll = long long;

const int maxN = 2e5 + 5;
const int MOD = 1e9 + 7;


int main() {
   freopen("../input.txt", "r", stdin);
   freopen("../output.txt", "w", stdout);
   InTheNameOfGod;
    
    int n,m,k;
    cin >> n >> m >> k;

    vector<vector<int> > g(n+1), tav(n+1, vector<int>(2, -1));
    vector<int> a(k);

    for(int &i : a) cin >> i;

    for(int i = 0; i < m; i++) {
        int x,y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    vector<vector<int> > pref(2*n+1, vector<int>(2, 0));

    for(int i = 0; i < k; i++) {
        if(g[a[i]].size() > 0) {
            tav[a[i]][0] = 1;
            pref[1][0]++;
        }
        else {
            pref[1][0]++;
            pref[2][0]--;
        }
    }

    queue<pair<int, int >> sor;
    for(int i : a) sor.push({i, 0});

    while(!sor.empty()) {
        pair<int, int> cur = sor.front();
        sor.pop();

        //cout << cur.first << ", " << cur.second << ": " << tav[cur.first][cur.second] << endl;

        for(int sz : g[cur.first]) {
            if(tav[sz][1-cur.second] != -1) continue;
            tav[sz][1-cur.second] = tav[cur.first][cur.second] + 1;
            pref[tav[sz][1-cur.second]][1-cur.second]++;
            sor.push({sz, 1-cur.second});
        }
    }

    /*for(int i = 1; i < 7; i++) cout << pref[i][0] << ' ';
    cout << endl;
    for(int i = 1; i < 7; i++) cout << pref[i][1] << ' ';
    cout << endl;*/

    vector<int> mo(2*n+1, 0);
    int maxi = -1, ind = -1;
    for(int i = 1; i < mo.size(); i++) {
        mo[i] = pref[i][1-i%2];
        if(i > 2) mo[i] += mo[i-2];

        if(mo[i] > maxi) {
            maxi = mo[i];
            ind = i;
        }
    }
    cout << maxi << "\n" << ind << "\n";
    for(int i = 1; i <= ind; i++) cout << mo[i] << ' ';

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/100
1Runtime error0/04ms2028 KiB
2Runtime error0/03ms2080 KiB
3Runtime error0/23ms2092 KiB
4Runtime error0/24ms2088 KiB
5Runtime error0/24ms2080 KiB
6Runtime error0/24ms2092 KiB
7Runtime error0/43ms2100 KiB
8Runtime error0/43ms2080 KiB
9Runtime error0/44ms2080 KiB
10Runtime error0/44ms2088 KiB
11Runtime error0/44ms2076 KiB
12Runtime error0/43ms2088 KiB
13Runtime error0/44ms2092 KiB
14Runtime error0/44ms2096 KiB
15Runtime error0/64ms2132 KiB
16Runtime error0/64ms2088 KiB
17Runtime error0/64ms2092 KiB
18Runtime error0/64ms2132 KiB
19Runtime error0/64ms2128 KiB
20Runtime error0/63ms2128 KiB
21Runtime error0/64ms2132 KiB
22Runtime error0/63ms2132 KiB
23Runtime error0/64ms2124 KiB
24Runtime error0/64ms2132 KiB