QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#67631 | #5017. 相等树链 | Dual | 0 | 0ms | 0kb | C++ | 1.3kb | 2022-12-10 21:06:22 | 2022-12-10 21:06:23 |
Judging History
answer
#include <bits/stdc++.h>
#define fr(i,j,k) for(register int i=j;i<=k;++i)
using namespace std;
typedef unsigned long long ull;
int n;
random_device rd;
mt19937_64 Rnd(1919810);
namespace Subtask1 {
const int N = 5e3 + 5;
ull val[N];
int ans;
vector<int> G1[N], G2[N];
ull dis1[N], dis2[N];
vector<ull> v1, v2;
unordered_set<ull> S;
void dfs1(int x, int fa, ull now)
{
// cout << x << ' ' << fa << ' ' << now << endl;
now ^= val[x];
S.insert(now);
for (auto y : G1[x]) {
if (y == fa) continue;
dfs1(y, x, now);
}
}
void dfs2(int x, int fa, ull now)
{
// cout << x << ' ' << fa << ' ' << now << endl;
now ^= val[x];
ans += S.count(now);
for (auto y : G2[x]) {
if (y == fa) continue;
dfs2(y, x, now);
}
}
void Main()
{
for (int i = 2; i <= n; i++)
{
int x;
cin >> x;
G1[x].push_back(i);G1[i].push_back(x);
}
for (int i = 2; i <= n; i++)
{
int x;
cin >> x;
G2[x].push_back(i);G2[i].push_back(x);
}
for (int i = 1; i <= n; i++) val[i] = Rnd();
fr(i, 1, n) dfs1(i, 0, 0);
fr(i, 1, n) dfs2(i, 0, 0);
// v1.reserve(n * (n - 1) / 2);
// v2.reserve(n * (n - 1) / 2);
cout << (ans+n)/2 << endl;
}
}
int main()
{
cin >> n;
Subtask1::Main();
return 0;
}
详细
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
5000 1296 1400 867 4533 1296 2007 2059 115 821 2960 3187 1597 2409 2708 4743 4778 1345 3967 911 3400 4249 3793 339 3145 3490 607 4148 3513 3264 3852 568 775 828 1348 423 3678 305 1938 1096 1373 2662 1048 4328 4208 203 779 3103 3372 4523 192 264 792 4943 2211 2494 3513 3555 4935 3277 3390 4624 128 18...
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #6:
score: 0
Runtime Error
input:
200000 13177 40498 104798 83659 186055 32788 86489 72123 13521 134868 158968 60124 166316 163390 120935 103000 83938 57807 97940 40447 137723 154683 191864 59080 102808 3969 21451 165592 128776 49468 4101 26441 139317 59503 18053 118809 187783 149816 21609 98521 165692 52964 60425 23437 29614 106886...
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%