QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#883663#10053. Post OfficeProjectCF0 25ms15816kbC++141.4kb2025-02-05 17:54:382025-02-05 17:54:39

Judging History

This is the latest submission verdict.

  • [2025-02-05 17:54:39]
  • Judged
  • Verdict: 0
  • Time: 25ms
  • Memory: 15816kb
  • [2025-02-05 17:54:38]
  • Submitted

answer

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stdlib.h>
#include <time.h>
#include <map>
#include <complex>
#include <math.h>
#include <stack>
#include <unordered_map>
#include <set>
#include <string.h>
#include <iomanip>
#include <bitset>
#include <random>
using namespace std;
//#define int long long
#define P make_pair
#define A first
#define B second
typedef pair<int, int> pii;
int fa[200010];
priority_queue<pii> q[200010];
signed main() {
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)cin >> fa[i];
    int m, ok = 1;
    cin >> m;
    for (int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
        int c = a, d = 0;
        while (1) {
            if (c == b)break;
            c = fa[c];
            d++;
            if (d == n)break;
        }
        if (d == n)ok = 0;
        else q[a].push(P(d, b));
    }
    if (ok == 0) {
        cout << -1 << endl;
        return 0;
    }
    int ans = 0;
    while (1) {
        ok = 1;
        for (int i = 1; i <= n; i++) {
            if (!q[i].empty() && q[i].top().A != 0)ok = 0, q[fa[i]].push(P(q[i].top().A - 1, q[i].top().B)), q[i].pop();
        }
        if (!ok)ans++;
        else {
            cout << ans << endl;
            return 0;
        }
    }
    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 9840kb

input:

3000
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 1...

output:

2

result:

wrong answer 1st lines differ - expected: '1119', found: '2'

Subtask #2:

score: 0
Wrong Answer

Test #8:

score: 9
Accepted
time: 0ms
memory: 10496kb

input:

5
2 1 1 3 1
5
1 2
4 1
5 1
3 1
4 1

output:

3

result:

ok single line: '3'

Test #9:

score: 9
Accepted
time: 1ms
memory: 9820kb

input:

5
2 1 2 3 3
5
3 2
5 2
5 1
4 2
2 1

output:

4

result:

ok single line: '4'

Test #10:

score: 9
Accepted
time: 0ms
memory: 9948kb

input:

5
2 1 1 2 4
5
5 1
4 1
3 2
5 2
4 2

output:

4

result:

ok single line: '4'

Test #11:

score: 9
Accepted
time: 0ms
memory: 9856kb

input:

5
2 1 1 1 1
5
1 2
3 1
2 1
4 2
2 1

output:

2

result:

ok single line: '2'

Test #12:

score: 9
Accepted
time: 0ms
memory: 9804kb

input:

5
2 1 1 2 4
5
3 1
5 2
1 2
3 1
4 2

output:

2

result:

ok single line: '2'

Test #13:

score: 9
Accepted
time: 0ms
memory: 10780kb

input:

5
2 1 1 1 2
5
5 2
3 2
3 1
5 2
2 1

output:

2

result:

ok single line: '2'

Test #14:

score: 9
Accepted
time: 1ms
memory: 10436kb

input:

5
2 1 2 2 4
5
2 1
5 2
3 2
5 1
2 1

output:

3

result:

ok single line: '3'

Test #15:

score: 9
Accepted
time: 1ms
memory: 9884kb

input:

5
2 1 2 3 4
5
4 1
5 2
5 2
3 1
1 2

output:

4

result:

ok single line: '4'

Test #16:

score: 9
Accepted
time: 1ms
memory: 10056kb

input:

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

output:

7

result:

ok single line: '7'

Test #17:

score: 0
Wrong Answer
time: 2ms
memory: 10036kb

input:

10
2 3 4 5 1 2 6 5 8 1
10
3 4
10 2
4 1
6 2
10 4
4 1
7 1
5 1
10 3
1 3

output:

4

result:

wrong answer 1st lines differ - expected: '6', found: '4'

Subtask #3:

score: 0
Time Limit Exceeded

Test #34:

score: 13
Accepted
time: 23ms
memory: 15816kb

input:

2
1 1
200000
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1...

output:

200000

result:

ok single line: '200000'

Test #35:

score: 0
Time Limit Exceeded

input:

200000
1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...

output:


result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #41:

score: 0
Time Limit Exceeded

input:

200000
1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...

output:


result:


Subtask #5:

score: 0
Time Limit Exceeded

Test #51:

score: 11
Accepted
time: 25ms
memory: 11436kb

input:

2
2 1
200000
2 1
2 1
1 2
2 1
1 2
1 2
2 1
1 2
1 2
2 1
2 1
1 2
2 1
2 1
1 2
1 2
2 1
1 2
1 2
2 1
2 1
1 2
1 2
1 2
2 1
2 1
2 1
2 1
1 2
2 1
2 1
2 1
1 2
2 1
1 2
1 2
1 2
1 2
2 1
2 1
2 1
2 1
1 2
2 1
1 2
1 2
1 2
2 1
1 2
1 2
1 2
1 2
2 1
2 1
2 1
1 2
1 2
1 2
2 1
2 1
1 2
1 2
1 2
1 2
1 2
1 2
1 2
2 1
1 2
1 2
2 1
2 1...

output:

100031

result:

ok single line: '100031'

Test #52:

score: 0
Time Limit Exceeded

input:

200000
200000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 9...

output:


result:


Subtask #6:

score: 0
Time Limit Exceeded

Test #60:

score: 0
Time Limit Exceeded

input:

200000
1 1 1 3 3 2 5 3 4 6 9 3 3 9 14 13 4 2 18 9 3 11 20 13 7 13 14 6 13 2 22 14 5 9 19 7 28 22 10 37 37 26 15 39 18 31 18 19 22 6 4 22 29 30 43 38 33 39 19 10 14 25 35 5 3 50 34 13 60 44 31 47 67 27 52 26 48 30 18 63 76 80 49 16 39 16 59 77 60 26 84 50 54 36 75 77 72 77 1 45 13 20 86 19 56 9 47 82...

output:


result:


Subtask #7:

score: 0
Time Limit Exceeded

Test #97:

score: 0
Time Limit Exceeded

input:

200000
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...

output:


result: