QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#568110#9310. Permutation Counting 4lanhuoWA 0ms3588kbC++17614b2024-09-16 15:16:472024-09-16 15:16:48

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 14:56:40]
  • hack成功,自动添加数据
  • (/hack/835)
  • [2024-09-18 14:41:06]
  • hack成功,自动添加数据
  • (/hack/831)
  • [2024-09-17 12:14:52]
  • hack成功,自动添加数据
  • (/hack/825)
  • [2024-09-16 15:16:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3588kb
  • [2024-09-16 15:16:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
typedef long long ll;
#define pll pair<ll,ll>
const int N=1e6+5;
ll n,f[N],ans;
ll find(ll x){
	return f[x]==x?x:f[x]==find(f[x]);
}
void solve(){
	cin>>n;
	for(int i=0;i<=n;++i)f[i]=i;
	ans=1;
	for(int i=1;i<=n;++i){
		ll l,r;cin>>l>>r;
		--l;
		if(find(l)==find(r))ans=0;
		else f[find(l)]=find(r);
	}
	cout<<ans<<endl;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;cin>>t;
    while(t--){
    	solve();
	}
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3588kb

input:

4
5
1 2
1 5
1 2
1 2
2 2
5
1 1
2 4
2 3
5 5
3 4
5
3 5
1 2
3 4
3 5
3 3
5
1 5
1 4
4 5
5 5
1 2

output:

1
1
1
1

result:

wrong answer 1st words differ - expected: '0', found: '1'