99162024-03-18 16:44:04111Pletykacpp17Runtime error 0/100103ms54700 KiB
#include <bits/stdc++.h>
using namespace std;

#ifndef ONLINE_JUDGE
#define dbg cout
#else
struct _dbg{}dbg;
_dbg&operator<<(_dbg&,auto){}
_dbg&operator<<(_dbg&,ostream&(*)(ostream&)){}
#endif

#define int long long

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=1;i<=N;i++){
		dbg<<v[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;
					d[i+1].push_back(k);
				}
			}
		}
    }
    vector<array<int,2>>b(it);
    vector<int>pf(it);
    for(int i=1;i<=N;i++){
		if(v[i]==-1){
			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];
		dbg<<setw(3)<<ans[i]<<' ';
    }
    dbg<<endl;
    int P=max_element(ans.begin(),ans.end())-ans.begin();
    cout<<ans[P]<<'\n';
    cout<<P+1<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/100
1Runtime error0/03ms1928 KiB
2Runtime error0/017ms13304 KiB
3Runtime error0/23ms2908 KiB
4Runtime error0/23ms3324 KiB
5Runtime error0/24ms4040 KiB
6Runtime error0/24ms5308 KiB
7Runtime error0/44ms5604 KiB
8Runtime error0/47ms7560 KiB
9Runtime error0/47ms7556 KiB
10Runtime error0/47ms7832 KiB
11Runtime error0/417ms15480 KiB
12Runtime error0/417ms15816 KiB
13Runtime error0/428ms23596 KiB
14Runtime error0/428ms24016 KiB
15Runtime error0/637ms32172 KiB
16Runtime error0/637ms32968 KiB
17Runtime error0/648ms41064 KiB
18Runtime error0/648ms42096 KiB
19Runtime error0/654ms46852 KiB
20Runtime error0/654ms48132 KiB
21Runtime error0/654ms49368 KiB
22Runtime error0/659ms50736 KiB
23Runtime error0/697ms54692 KiB
24Runtime error0/6103ms54700 KiB