Skip to content

Instantly share code, notes, and snippets.

@behitek
Created October 23, 2016 05:35
Show Gist options
  • Save behitek/7d733d2014736199d6bd1b3b95696bbf to your computer and use it in GitHub Desktop.
Save behitek/7d733d2014736199d6bd1b3b95696bbf to your computer and use it in GitHub Desktop.
P145SUMH
#include <bits/stdc++.h>
#define _for(i,a,b) for (int i=(a),_b_=(b);i<_b_;i++)
#define _fod(i,a,b) for (int i=(a),_b_=(b);i>_b_;i--)
#define _it(i,v) for (typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i)
#define _all(v) v.begin(), v.end()
#define __(v) memset(v,0,sizeof(v))
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
template<typename T> vector<T> &operator += (vector<T> &v, T x) {v.push_back(x);return v;}
void solve() {
int n,m,h;
cin>>n>>m>>h;
int arr[n];
_for(i,0,n) arr[i] = n+5;
int a;
_for(i,0,m){
cin>>a;
arr[a] = 0;
}
int u,v;
_for(i,0,h){
cin>>u>>v;
arr[v] = min(arr[v],arr[u]+1);
arr[u] = min(arr[u],arr[v]+1);
}
_for(i,0,h){
arr[v] = min(arr[v],arr[u]+1);
arr[u] = min(arr[u],arr[v]+1);
}
int max = 0, ans = n;
for(int i = 0;i < n;i++){
if(arr[i] > max){
max = arr[i];
ans = i;
}
}
cout<<ans<<endl;
}
int main(){
#ifdef HieuNguyen
freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment