Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //STATUS:C++_AC_828MS_11284KB
- #include <functional>
- #include <algorithm>
- #include <iostream>
- //#include <ext/rope>
- #include <fstream>
- #include <sstream>
- #include <iomanip>
- #include <numeric>
- #include <cstring>
- #include <cassert>
- #include <cstdio>
- #include <string>
- #include <vector>
- #include <bitset>
- #include <queue>
- #include <stack>
- #include <cmath>
- #include <ctime>
- #include <list>
- #include <set>
- //#include <map>
- using namespace std;
- //#pragma comment(linker,"/STACK:102400000,102400000")
- //using namespace __gnu_cxx;
- //define
- #define pii pair<int,int>
- #define mem(a,b) memset(a,b,sizeof(a))
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- #define PI acos(-1.0)
- //typedef
- typedef long long LL;
- typedef unsigned long long ULL;
- //const
- const int N=1010;
- const int INF=0x3f3f3f3f;
- const int MOD=1e9+7,STA=8000010;
- //const LL LNF=1LL<<60;
- const double EPS=1e-8;
- const double OO=1e15;
- const int dx[4]={-1,0,1,0};
- const int dy[4]={0,1,0,-1};
- const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
- //Daily Use ...
- inline int sign(double x){return (x>EPS)-(x<-EPS);}
- template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
- template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
- template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
- template<class T> inline T Min(T a,T b){return a<b?a:b;}
- template<class T> inline T Max(T a,T b){return a>b?a:b;}
- template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
- template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
- template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
- template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
- //End
- struct Edge{
- int u,v;
- }e[N*10*2];
- int first[N],next[N*10*2],vis[N],hig[N];
- int n,m,L,mt;
- void adde(int a,int b)
- {
- e[mt].u=a,e[mt].v=b;
- next[mt]=first[a],first[a]=mt++;
- e[mt].u=b,e[mt].v=a;
- next[mt]=first[b],first[b]=mt++;
- }
- queue<int> q;
- void bfs()
- {
- int i,j,u,v;
- while(!q.empty())
- {
- u=q.front();q.pop();
- for(i=first[u];i!=-1;i=next[i]){
- v=e[i].v;
- if(vis[v])continue;
- vis[v]=1;
- hig[v]=hig[u]+1;
- q.push(v);
- }
- }
- }
- int main()
- {
- // freopen("in.txt","r",stdin);
- int i,j,k,a,b,c;
- while(~scanf("%d%d%d",&n,&m,&L))
- {
- mem(first,-1);mt=0;
- mem(hig,INF);
- mem(vis,0);
- for(i=0;i<m;i++){
- scanf("%d",&a);
- hig[a]=0;
- q.push(a);
- vis[a]=1;
- }
- for(i=0;i<L;i++){
- scanf("%d%d",&a,&b);
- adde(b,a);
- }
- bfs();
- int ans=0,answ=0;
- for(i=0;i<n;i++){
- if(hig[i]>ans){
- ans=hig[i];
- answ=i;
- }
- }
- printf("%d\n",answ);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement