QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#565174#9310. Permutation Counting 4red_jiuWA 0ms5640kbC++17897b2024-09-15 20:30:112024-09-15 20:30:11

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-15 20:30:11]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5640kb
  • [2024-09-15 20:30:11]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6 + 10;
const int MOD = 998244353;
typedef pair<ll, ll> PLL;
typedef pair<int, int > PII;
typedef pair<double, double> PDD;
ll n, zu[N];
pair<ll, ll>s[N];
ll find(ll x) { return x == zu[x] ? x : zu[x] = find(zu[x]); }
void solve(){
	cin >> n;
	for (int i = 1; i <= n + 1; i++)
		zu[i] = i;
	for (int i = 1; i <= n; i++)
	{
		cin >> s[i].first >> s[i].second;
		//s[i].second++;
	}
	for (int i = 1; i <= n; i++)
	{
		ll x = find(s[i].first), y = find(s[i].second);
		if (x == y)
		{
			cout << "0\n";
			return;
		}
		zu[x] = y;
	}
	cout << "1\n";
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int T = 1;
	cin >> T;
	while (T--){
		solve();
	}
	return 0;
}













Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
0
0
0

result:

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