QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#572956#9310. Permutation Counting 4lurekiaWA 0ms3800kbC++141002b2024-09-18 16:55:492024-09-18 16:55:50

Judging History

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

  • [2024-09-18 16:55:50]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3800kb
  • [2024-09-18 16:55:49]
  • 提交

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'