QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#597943#9310. Permutation Counting 4Jin_ChuantiRE 0ms0kbC++14523b2024-09-28 19:32:422024-09-28 19:32:42

Judging History

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

  • [2024-09-28 19:32:42]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-28 19:32:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N = 1e6 + 10;
int a[N] = {0};

int find(int n){
	if(a[n] == n) return n;
	else a[n] = find(a[n]);
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t, n, l, r, jg;
	cin >> t;
	while(t--){
		cin >> n;
		jg = 1;
		for(int i = 0; i <= n; i++)	a[i] = i;
		for(int i = 0; i <= n; i++){
			cin >> l >> r;
			if(find(l - 1) == find(r)) jg = 0;
			else a[find(l - 1)] = find(r); 
		}
		printf("%d\n",jg);
	}
 	return 0;
}

详细

Test #1:

score: 0
Runtime Error

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:


result: