比赛 |
ZLXSCDay2 |
评测结果 |
AAAAAAAAAA |
题目名称 |
黑心买卖 |
最终得分 |
100 |
用户昵称 |
Zayin |
运行时间 |
1.723 s |
代码语言 |
C++ |
内存使用 |
9.55 MiB |
提交时间 |
2016-04-10 15:49:07 |
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define maxn 200005
#define maxm 1000050
#define next nxt
using namespace std;
int n,m,tot=0;
int v[maxn],fa[maxn];
bool vis[maxn],ans[maxn];
int head[maxn],edge[maxm],next[maxm];
void join(int u,int v)
{
edge[tot]=v; next[tot]=head[u]; head[u]=tot++;
edge[tot]=u; next[tot]=head[v]; head[v]=tot++;
}
void init()
{
memset(head,-1,sizeof(head));
scanf("%d%d",&n,&m);
for (int i=0;i<m;++i)
{
int u,v;
scanf("%d%d",&u,&v);
join(u,v);
}
for (int i=n;i;--i)
{
scanf("%d",&v[i]);
fa[i]=i;
}
}
int find(int x)
{
return fa[x]==x?x:fa[x]=find(fa[x]);
}
void solve()
{
int i,cnt=0;
for (int p=1;p<=n;++p)
{
vis[i=v[p]]=1;
++cnt;
for (int k=head[i];k!=-1;k=next[k])
{
int j=edge[k];
if (!vis[j]) continue;
int father=find(j);
// cout<<" "<<j<<" "<<father<<endl;
if (father!=i)
--cnt,
fa[father]=i;
}
/*cout<<i<<" "<<cnt<<endl;
for (int i=1;i<=n;++i)
cout<<fa[i]<<"("<<vis[i]<<") ";
cout<<endl;*/
ans[p]=(cnt==1);
}
for (int i=n;i;--i)
printf(ans[i]?"YES\n":"NO\n");
}
int main()
{
freopen("closing.in","r",stdin);
freopen("closing.out","w",stdout);
init();
solve();
return 0;
}