99212024-03-18 16:58:16111Pletykacpp17Time limit exceeded 88/100128ms54012 KiB
#include <bits/stdc++.h>
using namespace std;

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef CB
	freopen("be2.txt","r",stdin);
//	freopen("out.txt","w",stdout);
#endif
    int N,M,K;
    cin>>N>>M>>K;
    int it=N*2+2;
    vector<int>v(N+1,-1);
    deque<int>q;
    for(int i=0;i<K;i++){
		int a;
		cin>>a;
		v[a]=0;
		q.push_back(a);
    }
    vector<vector<int>>g(N+1);
    for(int i=0;i<M;i++){
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
    }
    while(!q.empty()){
		int i=q.front();
		q.pop_front();
		for(int j:g[i]){
			if(v[j]==-1){
				v[j]=v[i]+1;
				q.push_back(j);
			}
		}
    }
    vector<vector<int>>d(it);
    vector<int>w(N+1,-1);
    for(int i=0;i<it;i++){
    	d[i].reserve(8);
    }
    for(int i=1;i<=N;i++){
		if(v[i]==-1){
			continue;
		}
		int x=INT_MAX;
		for(int j:g[i]){
			if(v[j]>=v[i]&&v[j]%2==v[i]%2){
				x=min(x,v[j]);
			}
		}
		if(x!=INT_MAX){
			w[i]=x;
			d[x].push_back(i);
		}
    }
    for(int i=0;i<it;i++){
		for(int j:d[i]){
			if(w[j]<i){
				continue;
			}
			for(int k:g[j]){
				if(w[k]==-1||w[k]>i+1){
					w[k]=i+1;
					d[i+1].push_back(k);
				}
			}
		}
    }
    vector<array<int,2>>b(it);
    vector<int>pf(it);
    int e=0;
    for(int i=1;i<=N;i++){
		if(v[i]==-1){
			continue;
		}
		if (g[i].empty()){
			e++;
			continue;
		}
		b[v[i]][v[i]%2]++;
		if(w[i]==-1){
			continue;
		}
		b[w[i]][v[i]%2]--;
		pf[w[i]]++;
    }
    vector<int>ans(it);
    array<int,2>c{};
    for(int i=0;i<it;i++){
		c[0]+=b[i][0]+pf[i];
		c[1]+=b[i][1]+pf[i];
		ans[i]=c[i%2];
    }
    ans[0]+=e;
    int P=max_element(ans.begin(),ans.end())-ans.begin();
    cout<<ans[P]<<'\n';
    cout<<P+1<<'\n';
    for(int i=0;i<=P;i++){
		cout<<ans[i]<<' ';
    }
    cout<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base88/100
1Accepted0/03ms1824 KiB
2Accepted0/028ms16192 KiB
3Accepted2/23ms2536 KiB
4Accepted2/23ms2968 KiB
5Accepted2/24ms3668 KiB
6Accepted2/26ms5080 KiB
7Accepted4/46ms5088 KiB
8Accepted4/49ms7656 KiB
9Accepted4/48ms7748 KiB
10Accepted4/48ms7756 KiB
11Accepted4/428ms17192 KiB
12Accepted4/428ms17308 KiB
13Accepted4/441ms26756 KiB
14Accepted4/443ms26820 KiB
15Accepted6/661ms36576 KiB
16Accepted6/661ms36672 KiB
17Accepted6/675ms46072 KiB
18Accepted6/674ms46716 KiB
19Accepted6/676ms51020 KiB
20Accepted6/678ms51464 KiB
21Accepted6/679ms51748 KiB
22Accepted6/682ms51660 KiB
23Time limit exceeded0/6128ms53932 KiB
24Time limit exceeded0/6128ms54012 KiB