11972022-03-15 20:27:38k_balintPletykacpp14Wrong answer 0/100108ms31872 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));
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin>>n>>m>>k;

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

    for(int i=1;i<=m;i++){
        int a,b; cin>>a>>b;
        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 << maxi+1 << '\n';
    for(int i=0;i<=maxi;i++){
        cout << ans[i] << ' ';
    }
}
SubtaskSumTestVerdictTimeMemory
base0/100
1Wrong answer0/04ms6516 KiB
2Wrong answer0/020ms9180 KiB
3Wrong answer0/23ms6848 KiB
4Wrong answer0/24ms6892 KiB
5Wrong answer0/24ms7064 KiB
6Wrong answer0/24ms7316 KiB
7Wrong answer0/44ms7368 KiB
8Wrong answer0/48ms7884 KiB
9Wrong answer0/48ms7964 KiB
10Wrong answer0/47ms8060 KiB
11Wrong answer0/423ms9944 KiB
12Wrong answer0/420ms10092 KiB
13Wrong answer0/432ms12164 KiB
14Wrong answer0/435ms12864 KiB
15Wrong answer0/650ms15240 KiB
16Wrong answer0/646ms16040 KiB
17Wrong answer0/656ms18416 KiB
18Wrong answer0/650ms19456 KiB
19Wrong answer0/657ms21084 KiB
20Wrong answer0/657ms22244 KiB
21Wrong answer0/656ms23400 KiB
22Wrong answer0/671ms24716 KiB
23Wrong answer0/6108ms29460 KiB
24Wrong answer0/6104ms31872 KiB