Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cstdio>
- #include<vector>
- #include<deque>
- #include<cstrign>
- using namespace std;
- vector<int> a[100001];
- vector<int>::iterator it;
- deque<pair<int,int> > cd;
- int i, n, m, x, y, val[100001], nr, sol;
- pair<int,int> p;
- bool ok[100001], merge, viz[100001];
- int main(){
- freopen("a.in","r",stdin);
- freopen("a.out","w",stdout);
- scanf("%d%d", &n, &m);
- for (i=1;i<=m;i++) {
- scanf("%d%d", &x, &y); a[x].push_back(y); a[y].push_back(x);
- }
- scanf("%d", &val[0]); for (i=1;i<=val[0];i++) scanf("%d", &val[i]);
- scanf("%d", &nr); for (i=1;i<=nr;i++) {scanf("%d", &x); ok[x]=true;}
- for (i=1;i<=val[0];i++) {
- cd.clear(); merge=true; memset(viz, false, sizeof(viz));
- viz[val[i]]=true;
- for (it=a[val[i]].begin();it!=a[val[i]].end();it++)
- cd.push_back(make_pair(*it, 1));
- while (merge==true) {
- p=cd.front();
- for (it=a[x].begin();it!=a[x].end();it++)
- if (!viz[*it])
- cd.push_back(make_pair(*it, p.second+1));
- if (ok[p.first]==true) {merge=true; sol=p.second;}
- }
- printf("%d\n", sol);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement