QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#197958#6958. EquivalencePPP#WA 604ms138272kbC++171.7kb2023-10-02 22:44:172023-10-02 22:44:18

Judging History

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

  • [2023-10-02 22:44:18]
  • 评测
  • 测评结果:WA
  • 用时:604ms
  • 内存:138272kb
  • [2023-10-02 22:44:17]
  • 提交

answer

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
mt19937_64 rnd(228);
typedef unsigned long long ull;
const int maxN = 1e6 + 10;
ull f[maxN];
int n;
int p[maxN];
int val[maxN];
ull f0[maxN], f1[maxN];
int p2[maxN];
vector<int> g[maxN];
vector<int> g2[maxN];
void dfs(int v, int p) {
    f0[v] ^= f[v];
    for (int to : g[v]) {
        if (to == p) continue;
        dfs(to, v);
        f0[v] ^= f0[to];
    }
}
void dfs2(int v, int p) {
    f1[v] ^= f[v];
    for (int to : g2[v]) {
        if (to == p) continue;
        dfs2(to, v);
        f1[v] ^= f1[to];
    }
}
void solve() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        f[i] = rnd();
        f0[i] = f1[i] = 0;
        g[i].clear();
        g2[i].clear();
    }
    for (int i = 2; i <= n; i++) {
        cin >> p[i];
        g[i].emplace_back(p[i]);
        g[p[i]].emplace_back(i);
    }
    for (int i = 2; i <= n; i++) {
        cin >> val[i];
    }
    for (int i = 2; i <= n; i++) {
        cin >> p2[i];
        g2[i].emplace_back(p2[i]);
        g2[p2[i]].emplace_back(i);
    }
    dfs(1, -1);
    dfs2(1, -1);
    unordered_map<ull,int> mp;
    for (int i = 2; i <= n; i++) {
        mp[f1[i]]++;
    }
    int ans = 0;
    for (int i = 2; i <= n; i++) {
        if (val[i] > 0 && !mp.count(f[i])) {
            ans++;
        }
    }
    cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    int tst;
    cin >> tst;
    while (tst--) {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 604ms
memory: 138272kb

input:

8514
265000
72963 99588 118133 209949 249723 133275 171942 167920 86420 191069 169911 123458 176051 140795 122013 123039 252726 229192 52056 65706 247786 155474 231748 50060 24682 114313 43549 53896 73048 149564 51333 62885 117376 255302 235170 95044 56347 246767 193580 219540 227757 92735 173157 17...

output:

85639
32448
32394
187741
1654
1609
1579
1642
1624
1627
1605
1656
1615
1683
3
4
1
3
3
4
3
2
1
1
4
1
2
3
2
1
2
1
3
4
3
1
0
0
2
2
5
3
2
3
3
4
4
0
2
2
5
4
2
3
4
6
1
4
2
3
3
3
2
2
3
2
2
2
1
3
0
1
3
1
2
3
1
3
1
1
5
2
3
3
5
2
5
2
4
4
3
4
1
3
3
3
4
1
1
1
3
1
0
2
3
3
2
2
2
2
4
1
3
3
1
2
2
5
1
2
3
2
4
0
2
0
2...

result:

wrong answer 1st lines differ - expected: '75123', found: '85639'