求助,为什么会全re啊?
查看原帖
求助,为什么会全re啊?
1036760
yzk666楼主2024/1/15 11:31
#include<bits/stdc++.h>
using namespace std;
int n,m,t[3005],f[3005],sz[3005],ans[3005];
bool mp[3005][3005];
int find(int x){
	if(f[x]==x)   return x;
	else{
		return f[x];
	}
}
int mu(int x,int y){
	f[find(y)] = find(x);
	sz[find(x)] += sz[find(y)];
}
int main(){
	memset(f,-1,3003);
	cin>>n>>m;
	for(int i = 0;i<m;i++){
		int x,y;
		cin>>x>>y;
		mp[x][y] = 1;
		mp[y][x] = 1;
	}
	for(int i = 0;i<n;i++){
		sz[i] = 1;
		cin>>t[i];
	}
	for(int i = n-1;i>=0;i--){
		f[t[i]] = t[i];
		for(int j = 1;j<=n;j++){
			if(mp[t[i]][j]==1&&f[j]!=-1){
			    mu(t[i],j);
			}
		}
		if(sz[find(t[i])]==n-i)   ans[n-i]= 1;
		else   ans[n-i]= 0;
	}
	for(int i = n;i>0;i--){
		if(ans[i]==1)   cout<<"YES"<<endl;
		else   cout<<"NO"<<endl;
	}
	return 0;
}
2024/1/15 11:31
加载中...