11992022-03-15 20:34:33k_balintPletykacpp14Accepted 100/100104ms31884 KiB
#include <bits/stdc++.h>
using namespace std;
const int c=100005;

int n,m,k;
vector<int> adj[c];
bool vis[c][2];
queue<pair<int,int>> q;
vector<int> ans;
int isolated=0;

void bfs(){
    while(!q.empty()){
        int v=q.front().first;
        int d=q.front().second;
        if(d==1 && adj[v].empty()) isolated++;
        if(d==ans.size()+1){
            ans.emplace_back(1);
            if(d>=3) ans.back()+=ans[d-3];
            if(d==3) ans.back()-=isolated;
        }
        else ans.back()++;
        q.pop();

        ++d;
        for(int x:adj[v]){
            if(!vis[x][d&1]){
                vis[x][d&1]=1;
                q.push(make_pair(x,d));
            }
        }
    }
}

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(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    n=read(); m=read(); k=read();

    for(int i=1;i<=k;i++){
        int x=read();
        q.push(make_pair(x,1));
        vis[x][1]=1;
    }

    for(int i=1;i<=m;i++){
        int a,b; a=read(); b=read();
        adj[a].emplace_back(b);
        adj[b].emplace_back(a);
    }

    bfs();
    
    int maxi=0;
    for(int i=1;i<ans.size();i++){
        if(ans[maxi]<ans[i]) maxi=i;
    }

    cout << ans[maxi] << '\n' << maxi+1 << '\n';
    for(int i=0;i<=maxi;i++){
        cout << ans[i] << ' ';
    }
}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/04ms6536 KiB
2Accepted0/017ms9188 KiB
3Accepted2/23ms6864 KiB
4Accepted2/24ms6896 KiB
5Accepted2/24ms7072 KiB
6Accepted2/24ms7328 KiB
7Accepted4/44ms7372 KiB
8Accepted4/47ms7896 KiB
9Accepted4/46ms7968 KiB
10Accepted4/46ms8068 KiB
11Accepted4/414ms9952 KiB
12Accepted4/416ms10168 KiB
13Accepted4/423ms12168 KiB
14Accepted4/420ms12872 KiB
15Accepted6/634ms15184 KiB
16Accepted6/643ms15988 KiB
17Accepted6/646ms18356 KiB
18Accepted6/654ms19404 KiB
19Accepted6/648ms21056 KiB
20Accepted6/657ms22204 KiB
21Accepted6/646ms23364 KiB
22Accepted6/654ms24700 KiB
23Accepted6/682ms29480 KiB
24Accepted6/6104ms31884 KiB