QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#644016#2017. 排水系统remmymilkyway0 145ms12136kbC++142.0kb2024-10-16 09:52:472024-10-16 09:52:47

Judging History

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

  • [2024-10-16 09:52:47]
  • 评测
  • 测评结果:0
  • 用时:145ms
  • 内存:12136kb
  • [2024-10-16 09:52:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
void prt(__int128 x) {
    string s;
    while (x) {
        s += (char)('0' + x % 10);
        x /= 10;
    }
    if (s.empty()) {
        printf("0");
    }
    for (int i = (int)s.size() - 1; i >= 0; i--) {
        printf("%c", s[i]);
    }
}
struct frac {
    __int128 num, den;
    void yuefen() {
        __int128 g = __gcd(num, den);
        num /= g;
        den /= g;
    }
    friend frac operator+ (frac x, frac y) {
        frac res;
        __int128 g = __gcd(x.den, y.den);
        res.den = x.den / g * y.den;
        res.num = res.den / x.den * x.num + res.den / y.den * y.num;
        res.yuefen();
        return res;
    }
    friend frac operator/ (frac x, __int128 val) {
        __int128 g = __gcd(x.num, val);
        x.num /= g;
        x.den *= val / g;
        return x;
    }
};
int n, m, deg[maxn];
vector<int> G[maxn];
frac w[maxn];
int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++) {
        w[i].den = 1;
    }
    queue<int> q;
    for (int i = 1; i <= n; i++) {
        int d;
        scanf("%d", &d);
        for (int j = 1; j <= d; j++) {
            int a;
            scanf("%d", &a);
            G[i].push_back(a);
            deg[a]++;
        }
    }
    for (int i = 1; i <= m; i++) {
        q.push(i);
        w[i].num = 1;
    }
    while (!q.empty()) {
        int cur = q.front();
        q.pop();
        cout << cur << ' ';
        prt(w[cur].num);
        cout << ' ';
        prt(w[cur].den);
        cout << '\n';
        for (auto i : G[cur]) {
            w[i] = w[i] + (w[cur] / (int)G[cur].size());
            deg[i]--;
            if (deg[i] == 0) {
                q.push(i);
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        if (!(int)G[i].size()) {
            prt(w[i].num);
            printf(" ");
            prt(w[i].den);
            printf("\n");
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

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

input:

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

output:

1 1 1
2 1 4
3 1 4
4 1 4
5 1 4
6 1 12
7 5 12
9 1 4
8 13 24
10 1 1
1 1

result:

wrong answer Participant output contains extra tokens

Test #2:

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

input:

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

output:

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

result:

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

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 7340kb

input:

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

output:

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

result:

wrong answer 1st words differ - expected: '3', found: '1'

Test #4:

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

input:

1000 1
5 2 3 4 5 468
5 6 7 8 9 72
5 10 11 12 13 658
5 14 15 16 17 100
5 18 19 20 21 129
5 22 23 24 25 146
5 26 27 28 29 91
5 30 31 32 33 337
5 34 35 36 37 694
5 38 39 40 41 766
5 42 43 44 45 986
5 46 47 48 49 365
5 50 51 52 53 176
5 54 55 56 57 489
5 58 59 60 61 469
5 62 63 64 65 984
5 66 67 68 69 2...

output:

1 1 1
2 1 5
3 1 5
4 1 5
5 1 5
6 1 25
7 1 25
8 1 25
9 1 25
10 1 25
11 1 25
12 1 25
13 1 25
14 1 25
15 1 25
16 1 25
17 1 25
18 1 25
19 1 25
20 1 25
21 1 25
22 1 125
23 1 125
24 1 125
25 1 125
26 1 125
27 1 125
28 1 125
29 1 125
30 1 125
31 1 125
32 1 125
33 1 125
34 1 125
35 1 125
36 1 125
37 1 125
38...

result:

wrong answer 2nd words differ - expected: '625', found: '1'

Test #5:

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

input:

1000 1
5 2 3 4 5 257
5 6 7 8 9 948
5 10 11 12 13 633
5 14 15 16 17 1000
5 18 19 20 21 105
5 22 23 24 25 662
5 26 27 28 29 648
5 30 31 32 33 394
5 34 35 36 37 504
5 38 39 40 41 151
5 42 43 44 45 155
5 46 47 48 49 783
4 50 51 52 53
5 54 55 56 57 249
5 58 59 60 61 432
5 62 63 64 65 423
5 66 67 68 69 70...

output:

1 1 1
2 1 5
3 1 5
4 1 5
5 1 5
6 1 25
7 1 25
8 1 25
9 1 25
10 1 25
11 1 25
12 1 25
13 1 25
14 1 25
15 1 25
16 1 25
17 1 25
18 1 25
19 1 25
20 1 25
21 1 25
22 1 125
23 1 125
24 1 125
25 1 125
26 1 125
27 1 125
28 1 125
29 1 125
30 1 125
31 1 125
32 1 125
33 1 125
34 1 125
35 1 125
36 1 125
37 1 125
38...

result:

wrong answer 2nd words differ - expected: '625', found: '1'

Test #6:

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

input:

1000 1
5 2 3 4 5 799
5 6 7 8 9 587
5 10 11 12 13 694
5 14 15 16 17 865
5 18 19 20 21 10
5 22 23 24 25 69
5 26 27 28 29 337
5 30 31 32 33 607
5 34 35 36 37 989
5 38 39 40 41 291
5 42 43 44 45 309
5 46 47 48 49 44
5 50 51 52 53 854
5 54 55 56 57 209
5 58 59 60 61 502
5 62 63 64 65 597
5 66 67 68 69 60...

output:

1 1 1
2 1 5
3 1 5
4 1 5
5 1 5
6 1 25
7 1 25
8 1 25
9 1 25
11 1 25
12 1 25
13 1 25
14 1 25
15 1 25
16 1 25
17 1 25
18 1 25
19 1 25
20 1 25
21 1 25
10 2 25
22 1 125
23 1 125
24 1 125
25 1 125
26 1 125
27 1 125
28 1 125
29 1 125
30 1 125
31 1 125
32 1 125
33 1 125
34 1 125
35 1 125
36 1 125
37 1 125
42...

result:

wrong answer 2nd words differ - expected: '625', found: '1'

Test #7:

score: 0
Wrong Answer
time: 96ms
memory: 12060kb

input:

100000 1
5 2 3 4 5 7783
5 6 7 8 9 21991
5 10 11 12 13 45651
5 14 15 16 17 56745
5 18 19 20 21 84002
5 22 23 24 25 94984
5 26 27 28 29 16303
5 30 31 32 33 30894
5 34 35 36 37 37939
5 38 39 40 41 61574
5 42 43 44 45 72828
5 46 47 48 49 92611
5 50 51 52 53 11795
5 54 55 56 57 22587
5 58 59 60 61 36800
...

output:

1 1 1
2 1 5
3 1 5
4 1 5
5 1 5
6 1 25
7 1 25
8 1 25
9 1 25
10 1 25
11 1 25
12 1 25
13 1 25
14 1 25
15 1 25
16 1 25
17 1 25
18 1 25
19 1 25
20 1 25
21 1 25
22 1 125
23 1 125
24 1 125
25 1 125
26 1 125
27 1 125
28 1 125
29 1 125
30 1 125
31 1 125
32 1 125
33 1 125
34 1 125
35 1 125
36 1 125
37 1 125
38...

result:

wrong answer 2nd words differ - expected: '15625', found: '1'

Test #8:

score: 0
Wrong Answer
time: 102ms
memory: 11900kb

input:

100000 1
5 2 3 4 5 6025
5 6 7 8 9 32221
5 10 11 12 13 39240
5 14 15 16 17 55392
5 18 19 20 21 69386
5 22 23 24 25 97544
5 26 27 28 29 16414
5 30 31 32 33 32966
5 34 35 36 37 41376
5 38 39 40 41 66116
5 42 43 44 45 83340
5 46 47 48 49 90236
5 50 51 52 53 13716
5 54 55 56 57 32168
5 58 59 60 61 43106
...

output:

1 1 1
2 1 5
3 1 5
4 1 5
5 1 5
6 1 25
7 1 25
8 1 25
9 1 25
10 1 25
11 1 25
12 1 25
13 1 25
14 1 25
15 1 25
16 1 25
17 1 25
18 1 25
19 1 25
20 1 25
21 1 25
22 1 125
23 1 125
24 1 125
25 1 125
26 1 125
27 1 125
28 1 125
29 1 125
30 1 125
31 1 125
32 1 125
33 1 125
34 1 125
35 1 125
36 1 125
37 1 125
38...

result:

wrong answer 2nd words differ - expected: '12500', found: '1'

Test #9:

score: 0
Wrong Answer
time: 145ms
memory: 12020kb

input:

100000 10
5 11 12 13 14 15
3 66 67 68
4 96 97 98 99
5 1274 1643 2223 2242 2626
5 5407 8119 10748 19818 29900
5 178 180 316 323 1080
5 274 596 716 1923 2001
5 1497 8384 9739 16776 18532
5 165 211 240 289 985
5 170 179 197 222 1011
5 16 17 18 19 20
5 164 322 540 590 1641
5 340 4731 14181 50729 55910
5...

output:

1 1 1
2 1 1
3 1 1
4 1 1
5 1 1
6 1 1
7 1 1
8 1 1
9 1 1
10 1 1
11 1 5
12 1 5
13 1 5
14 1 5
15 1 5
66 1 3
67 1 3
68 1 3
96 1 4
97 1 4
98 1 4
99 1 4
1274 1 5
1643 1 5
2223 1 5
2242 1 5
2626 1 5
5407 1 5
8119 1 5
10748 1 5
19818 1 5
29900 1 5
178 1 5
180 1 5
316 1 5
323 1 5
1080 1 5
274 1 5
596 1 5
716 1...

result:

wrong answer 2nd words differ - expected: '48828125', found: '1'

Test #10:

score: 0
Wrong Answer
time: 145ms
memory: 12136kb

input:

100000 10
5 11 12 13 14 15
3 66 67 68
4 98 99 100 101
5 193 213 239 613 1656
5 187 259 453 513 3129
5 148 606 2076 5693 30126
5 748 1455 3800 4919 8049
5 264 419 516 868 1222
5 260 19073 24446 65904 50227
5 196 4456 4784 83171 95673
5 16 17 18 19 20
5 182 277 388 1070 2021
5 279 1317 4410 14701 2557...

output:

1 1 1
2 1 1
3 1 1
4 1 1
5 1 1
6 1 1
7 1 1
8 1 1
9 1 1
10 1 1
11 1 5
12 1 5
13 1 5
14 1 5
15 1 5
66 1 3
67 1 3
68 1 3
98 1 4
99 1 4
100 1 4
101 1 4
193 1 5
213 1 5
239 1 5
613 1 5
1656 1 5
187 1 5
259 1 5
453 1 5
513 1 5
3129 1 5
148 1 5
606 1 5
2076 1 5
5693 1 5
30126 1 5
748 1 5
1455 1 5
3800 1 5
4...

result:

wrong answer 2nd words differ - expected: '48828125', found: '1'