F

题目链接:https://vjudge.net/contest/162220#problem/F

题解:

1.利用数组标记坑

2.不是坑的交换

AC code:

#include <stdio.h>
#include <string.h>

int a[1000050],vis[1000050];

int main()
{
 int n,m,k;
 while(scanf("%d%d%d",&n,&m,&k)!=EOF)
 {
  memset(vis,0,sizeof(vis));
  for(int i=1;i<=m;i++)
  {
   scanf("%d",&a[i]);
   vis[a[i]]=1;
  }
  int x,y;
  int ans=1;
  for(int i=1;i<=k;i++)
  {
   scanf("%d%d",&x,&y);
   if(x==ans)
   {
    if(vis[x]!=1)
    {
     ans=y;
    }
   }
     else if(y==ans)
   {
    if(vis[y]!=1)
    {
     ans=x;
    }
   }
  }
  printf("%d ",ans);
 }
 return 0;
}

原文地址:https://www.cnblogs.com/DemonZiv/p/6818878.html