QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#313654 | #5667. Meeting Places | blln | WA | 1ms | 3740kb | C++11 | 773b | 2024-01-24 21:56:50 | 2024-01-24 21:56:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, m, o = 0, x, y, F[N], Dep[N], num[N], last[N], nxt[N];
int main() {
queue<int> tot;
tot.push(1);
scanf("%d %d", &n, &m);
for (int i = 2; i <= n; i++) scanf("%d", &F[i]), o++, nxt[o] = i, last[o] = num[F[i]], num[F[i]] = o;
while (!tot.empty()) {
x = tot.front();
tot.pop();
for (int i = num[x]; i; i = last[i]) Dep[nxt[i]] = Dep[x] + 1, tot.push(nxt[i]);
}
while (m--) {
scanf("%d %d", &x, &y);
while (x != y) {
if (Dep[x] > Dep[y])
x = F[x];
else if (Dep[x] < Dep[y])
y = F[y];
else
x = F[x], y = F[y];
}
printf("%d\n", x);
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3740kb
input:
100 23 213
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
wrong answer 1st numbers differ - expected: '1319350480.8007326', found: '0.0000000', error = '1.0000000'