QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#572956 | #9310. Permutation Counting 4 | lurekia | WA | 0ms | 3800kb | C++14 | 1002b | 2024-09-18 16:55:49 | 2024-09-18 16:55:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1000010;
void solve()
{
int n;
cin >> n;
vector<pair<int, int>> d(n + 1);
for (int i = 1; i <= n;i++)
cin >> d[i].first >> d[i].second;
d[0].first = 1;
d[0].second = 0;
vector<int> fa(n + 1);
for (int i = 0;i<=n;i++)
fa[i] = i;
auto find = [&](auto self, int u)
{
if(u == fa[u])
return u;
return fa[u] = self(self, fa[u]);
};
for (int i = 0; i < n;i++)
{
int u = d[i].first - 1;
int v = d[i + 1].second;
int fu = find(find, u);
int fv = find(find, v);
if(fu == fv)
{
cout << 0 << endl;
return;
}
fa[fu] = fv;
}
cout << 1 << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while(t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3800kb
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'