建议添加hack
  • 板块P11640 Graph
  • 楼主哈哈人生
  • 当前回复7
  • 已保存回复7
  • 发布时间2025/1/29 16:57
  • 上次更新2025/1/30 11:09:37
查看原帖
建议添加hack
782904
哈哈人生楼主2025/1/29 16:57

数据太水了吧,纯随机吧。

对于本人来说,我第一次脑抽不是判断奇环(二分图),而是单纯判断有没有环,结果直接过了。代码:

#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,n,m,a[1000005],b[1000005],c[1000005],fa[1000005],fa2[1000005];
int find(int x){
	if(fa[x]==x)return x;
	else return fa[x]=find(fa[x]);
}
int find2(int x){
	if(fa2[x]==x)return x;
	else return fa2[x]=find2(fa2[x]);
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>t;
	while(t--){
		cin>>n>>m;
		for(int i=1;i<=n;i++)fa[i]=i,fa2[i]=i;
		for(int i=1;i<=m;i++){
			cin>>a[i]>>b[i]>>c[i];
			if(c[i]%2==0)fa[find(a[i])]=find(b[i]);
		}
		bool pd=1;
		for(int i=1;i<=m;i++){
		    if(c[i]==0&&a[i]!=b[i]){
		        pd=0;
		        break;
		    }
			else if(c[i]%2==1){
				int x=find(a[i]),y=find(b[i]);
				if(x==y){
					pd=0;
					break;
				}
				else{
					int xx=find2(x),yy=find2(y);
					if(xx==yy){
						pd=0;
						break;
					}
					else fa2[xx]=find2(yy);
				}
			}
		}
		if(pd)cout<<"Yes\n";
		else cout<<"No\n";
	}
	return 0;
}

很容易发现,构造任意类似

in:
1
n n
1 2 1
2 3 1
...
n-1 n 1
n 1 1

的数据都能卡掉这个,例如对于

in:
1
4 4
1 2 1
2 3 1
3 4 1
4 1 1

正确输出为 Yes,程序输出为 No

另外,我还发现,若不小心把 find2 函数手滑打成 find 依然能 AC,而且以上数据还真不能hack住。

所以这题无论是 思路错误 还是 代码打错了关键字符都能 AC,这不应该吧,建议加强数据免得有人受害。

2025/1/29 16:57
加载中...