QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#566673#9310. Permutation Counting 4RapidsWA 0ms3696kbC++20624b2024-09-16 01:08:362024-09-16 01:08:36

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 01:08:36]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3696kb
  • [2024-09-16 01:08:36]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;
const int N = 1e6 + 10;

int p[N];

int find(int x) {
	return x == p[x] ? x : p[x] = find(p[x]);
}

void solve() {
	int n;
	std::cin >> n;
	for (int i = 0; i <= n; i++) {
		p[i] = i;
	}
	for (int i = 0; i < n; i++) {
		int x, y;
		std::cin >> x >> y;
		x = find(x - 1), y = find(y);
		if(x == y) {
			std::cout << 0 << '\n';
			return;
		}
		p[x] = y;
	}
	std::cout << 1 << '\n';
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0), std::cout.tie(0);

	int t;
	std::cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}

詳細信息

Test #1:

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

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:

0
1
1
1

result:

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