QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#602956#8720. BFS 序 0ITC_TL#WA 42ms28804kbC++201.5kb2024-10-01 13:47:022024-10-01 13:47:47

Judging History

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

  • [2024-10-01 13:47:47]
  • 评测
  • 测评结果:WA
  • 用时:42ms
  • 内存:28804kb
  • [2024-10-01 13:47:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fore(i, l, r) for (register int i = (int)l; i <= (int)r; i++)
#define ford(i, r, l) for (register int i = (int)r; i >= (int)l; i--)
const int MAXN = 2123456LL;
ll T, n, a[MAXN], fa[MAXN];
ll to[MAXN], nxt[MAXN], hand[MAXN], tot;
ll num[MAXN], b[MAXN];
ll mp[MAXN];
void add(ll x, ll y)
{
    tot++;
    to[tot] = y;
    nxt[tot] = hand[x];
    hand[x] = tot;
    return;
}
void sou(ll t)
{
    for (register int i = hand[t]; i; i = nxt[i])
    {
        num[to[i]] = num[t] + 1;
        sou(to[i]);
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    fore(i, 2, n)
    {
        cin >> fa[i];
        add(fa[i], i);
    }
    num[1] = 1;
    sou(1);
    ll q;
    cin >> q;
    ll m;
    while (q--)
    {
        cin >> m;
        bool p = 1;
        fore(i, 1, m)
        {
            cin >> b[i];
            mp[b[i]]++;
            if (mp[b[i]] >= 2)
                p = 0;
        }
        fore(i, 1, m) mp[b[i]] = 0, b[i] = num[b[i]];
        fore(i, 2, m)
        {
            if (b[i] < b[i - 1])
                p = 0;
        }
        if (p)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}
/*
6
1 1 3 2 4
10
4 3 6 2 5
1 4
3 2 4 5
5 2 5 4 6 3
3 1 4 2
3 5 6 3
5 4 5 2 6 1
4 4 3 2 5
4 4 6 2 3
3 3 2 6
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 13864kb

input:

6
1 1 3 2 4
10
4 3 6 2 5
1 4
3 2 4 5
5 2 5 4 6 3
3 1 4 2
3 5 6 3
5 4 5 2 6 1
4 4 3 2 5
4 4 6 2 3
3 3 2 6

output:

No
Yes
Yes
No
No
No
No
No
No
Yes

result:

ok 10 token(s): yes count is 3, no count is 7

Test #2:

score: -100
Wrong Answer
time: 42ms
memory: 28804kb

input:

300000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

No
Yes
Yes
Yes
No
No
No
No
No
No
Yes
Yes
No
Yes
No
Yes
Yes
Yes
No
No
No
No
Yes
No
No
Yes
No
No
No
No
Yes
Yes
Yes
No
No
Yes
No
No
No
No
No
No
No
Yes
No
Yes
No
Yes
No
No
No
No
Yes
Yes
Yes
No
No
Yes
No
No
No
No
No
Yes
Yes
No
No
No
No
No
Yes
Yes
No
Yes
No
No
No
Yes
No
No
Yes
No
No
Yes
Yes
Yes
Yes
No
No
...

result:

wrong answer expected NO, found YES [87th token]