12302022-03-27 11:49:23Szin AttilaPletykacpp14Accepted 100/100118ms43876 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;

inline int read(){
    int res=0; char ch=getchar();
    while(ch < '0' || '9' < ch) ch=getchar();
    while('0' <= ch && ch <= '9'){
        res=(res<<3) + (res<<1)+ch-'0';
        ch=getchar();
    }
    return res;
}


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

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

    for(int &i : a) i = read();

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

    vector<int > pref(n+3, 0);
    queue<pair<int, int > > sor;

    for(int i = 0; i < k; i++) {
        if(!g[a[i]].empty()) {
            tav[a[i]][0] = 1;
            pref[1]++;
            sor.push({a[i], 0});
        }
        else {
            pref[1]++;
            pref[3]--;
            //cout << "empty: " << a[i] << endl;
        }
    }

    while(!sor.empty()) {
        pair<int, bool> 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]]++;
            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(n+3, 0);
    mo[1] = pref[1];
    int maxi = mo[1], ind = 1;
    for(int i = 2; i < pref.size(); i++) { 
        mo[i] = pref[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] << ' ';
    cout << "\n";

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/02ms1820 KiB
2Accepted0/018ms9204 KiB
3Accepted2/21ms2216 KiB
4Accepted2/22ms2456 KiB
5Accepted2/22ms2716 KiB
6Accepted2/23ms3468 KiB
7Accepted4/44ms3520 KiB
8Accepted4/46ms4676 KiB
9Accepted4/44ms4772 KiB
10Accepted4/44ms4868 KiB
11Accepted4/417ms9908 KiB
12Accepted4/416ms10240 KiB
13Accepted4/427ms15432 KiB
14Accepted4/430ms16020 KiB
15Accepted6/648ms21440 KiB
16Accepted6/646ms22248 KiB
17Accepted6/678ms28040 KiB
18Accepted6/685ms29024 KiB
19Accepted6/679ms32660 KiB
20Accepted6/675ms33816 KiB
21Accepted6/696ms34964 KiB
22Accepted6/692ms36136 KiB
23Accepted6/6118ms41348 KiB
24Accepted6/6115ms43876 KiB