11402022-03-14 22:06:13k_balintPletykacpp14Wrong answer 51/100144ms33684 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[2];
int cnt[2];

void bfs(){
    while(!q.empty()){
        int v=q.front().first;
        int d=q.front().second+1;
        q.pop();

        for(int x:adj[v]){
            if(!vis[x][d&1]){
                vis[x][d&1]=1;
                ans[d&1].emplace_back(d);
                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;
        ans[1].emplace_back(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 last;
    if(ans[0].size()>ans[1].size()){
        cout << ans[0].size() << '\n' ;
        last=ans[0].back();
    }
    else if(ans[0].size() < ans[1].size()){
        cout << ans[1].size() << '\n';
        last=ans[1].back();
    }

    else {
        cout << ans[0].size() << '\n';
        last=min(ans[0].back(),ans[1].back());
    }

    cout << last << '\n';
    
    for(int i=1;i<=last;i++){
        int j=cnt[i&1];
        while(j<ans[i&1].size() && ans[i&1][j] <= i){
            ++j;
        }
        cnt[i&1]=j;

        cout << j << ' ';
    }
    cout << endl;
}
SubtaskSumTestVerdictTimeMemory
base51/100
1Accepted0/04ms6536 KiB
2Wrong answer0/024ms9580 KiB
3Accepted2/24ms6916 KiB
4Partially correct1/28ms7044 KiB
5Wrong answer0/24ms7096 KiB
6Wrong answer0/26ms7428 KiB
7Accepted4/46ms7492 KiB
8Wrong answer0/48ms8072 KiB
9Accepted4/48ms8016 KiB
10Accepted4/48ms8108 KiB
11Wrong answer0/420ms10320 KiB
12Accepted4/418ms10600 KiB
13Partially correct2/439ms12532 KiB
14Wrong answer0/448ms13460 KiB
15Wrong answer0/654ms15604 KiB
16Accepted6/650ms16372 KiB
17Wrong answer0/671ms19592 KiB
18Accepted6/671ms20364 KiB
19Accepted6/679ms21664 KiB
20Wrong answer0/6109ms23580 KiB
21Accepted6/693ms24508 KiB
22Accepted6/6104ms25704 KiB
23Time limit exceeded0/6144ms30952 KiB
24Time limit exceeded0/6136ms33684 KiB