QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#5405 | #2017. 排水系统 | Qingyu | 100 ✓ | 78ms | 11880kb | C++17 | 1.5kb | 2020-12-09 15:38:50 | 2021-12-19 06:16:39 |
Judging History
answer
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#define ll __int128
#define pb push_back
#define N 100005
using std::queue;
using std::vector;
int n, m, deg[N], id[N], top;
ll a[N], b[N];
vector<int> e[N];
inline ll gcd(ll a, ll b) {
while (b)
a %= b, std::swap(a, b);
return a;
}
queue<int> q;
inline void gtps(void) {
for (int i = 1; i <= n; ++i)
if (!deg[i])
q.push(i);
while (!q.empty()) {
int u = q.front();
q.pop();
id[++top] = u;
for (int i = 0; i < e[u].size(); ++i) {
int v = e[u][i];
ll ta = a[u], tb = b[u] * e[u].size();
a[v] = a[v] * tb + ta * b[v], b[v] *= tb;
ll d = gcd(a[v], b[v]);
b[v] /= d, a[v] /= d;
--deg[v];
if (!deg[v])
q.push(v);
}
}
}
inline void prt(ll x) {
if (x / 1000000000)
printf("%lld", (long long)(x / 1000000000));
printf((x / 1000000000 ? "%09lld" : "%lld"), (long long)(x % 1000000000));
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1, d; i <= n; ++i) {
b[i] = 1;
scanf("%d", &d);
for (int j = 1, x; j <= d; ++j)
scanf("%d", &x), ++deg[x], e[i].pb(x);
}
for (int i = 1; i <= m; ++i)
a[i] = 1;
gtps();
for (int i = 1; i <= n; ++i)
if (!e[i].size())
prt(a[i]), putchar(' '), prt(b[i]), putchar('\n');
return 0;
}
详细
Test #1:
score: 10
Accepted
time: 4ms
memory: 9148kb
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
result:
ok 2 tokens
Test #2:
score: 10
Accepted
time: 4ms
memory: 9172kb
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:
2 15 8 15 1 3
result:
ok 6 tokens
Test #3:
score: 10
Accepted
time: 3ms
memory: 8492kb
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:
3 20 2 5 9 20
result:
ok 6 tokens
Test #4:
score: 10
Accepted
time: 3ms
memory: 8696kb
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 201 5 70 71 72 73 832 5 74 75 76 77 515 5 78 79 80 81 82 5 82 83 84 85 753 5 86 87 88 89 509 5 90 91 92 93 899 5 94 95 96 97 814 5 98 99 100 101 643 5 102 103 104 105 743 5 106 107 108 109 700 5 110 11...
output:
1 625 1 625 1 625 1 625 1 625 1 625 1 625 1 3125 1 3125 2 3125 3 3125 2 3125 47 37500 1 2500 1 2500 2 3125 39 6250 2 3125 1 3125 626 3125 83 9375 26 3125 31 3125 2 3125 1 3125 9 6250 3 3125 9 12500 37 18750 1 3125 1 3125 2 3125 9 12500 1 3125 17 6250 33 3125 2 3125 3 3125 1 2500 9 12500 1 3125 13 12500 1 3125 3 3125 2 3125 3 2500 1 2500 21 2500 9 12500 13 12500 1 2500 6 3125 7 3125 11 3125 1 3125 2 3125 4 1875 9 12500 1 3125 13 12500 1 3125 17 6250 1 2500 1 500 29 12500 3 3125 1 3125 1 3125 1 25...
result:
ok 636 tokens
Test #5:
score: 10
Accepted
time: 4ms
memory: 9124kb
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 708 5 70 71 72 73 554 5 74 75 76 77 972 5 78 79 80 81 1000 5 82 83 84 85 895 5 86 87 88 89 734 5 90 91 92 93 805 5 94 95 96 97 565 5 98 99 100 101 876 5 102 103 104 105 182 5 106 107 108 109 806 5 110 1...
output:
1 625 1 625 6 625 2 625 1 625 1 625 1 625 1 625 1 625 1 625 1 500 1 1875 1 1250 1 2500 9 6250 1 2500 7 6250 8 9375 1 3125 1 375 1 2500 1 2000 1 1500 7 7500 4 1875 13 9375 2 3125 1 1500 1 1500 1 1500 1 1500 2 1875 1 1500 9 10000 1 2000 21 10000 9 2500 669 1000000 1 5000 2359 3000000 29 31250 23 15000 94 9375 23 46875 321 3125 21 12500 1 6250 3 6250 17 18750 79 37500 19 10000 121 56250 11 11250 27 2500 83 75000 501 250000 13 25000 89 50000 2087 3000000 89 200000 79 37500 2 3125 587 450000 1571 600...
result:
ok 626 tokens
Test #6:
score: 10
Accepted
time: 3ms
memory: 9156kb
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 5 70 71 72 73 229 5 74 75 76 77 307 5 78 79 80 81 607 5 82 83 84 85 739 5 86 87 88 89 234 5 90 91 92 93 196 5 94 95 96 97 939 4 98 99 100 101 5 102 103 104 105 801 4 106 107 108 109 5 110 111 112 113...
output:
1 625 1 625 1 625 1 625 1 625 1 625 2 625 6 625 9 6250 9 2500 1 2000 9 10000 1 2500 1 2500 1 2500 2 1875 3 1250 1 500 3 3125 47 37500 8 9375 1 3125 1 3125 1 750 67 37500 1 2500 3 3125 1 1250 1 300 2 3125 41 18750 2 1875 89 37500 11 9375 16 1875 8 9375 1 2500 1 2500 1 3125 29 6250 1 1000 1 1000 7 5000 31 18750 1 750 7 6250 1 3125 1 3125 1 3125 1 3125 59 25000 1 2500 9 12500 47 15000 9 12500 9 12500 9 6250 7 6250 9 12500 1 1875 9 12500 1 500 1 750 16 9375 8 9375 3 3125 1 1875 59 12500 1 2500 388 9...
result:
ok 652 tokens
Test #7:
score: 10
Accepted
time: 71ms
memory: 11728kb
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 5 62 63 64 65 59881 5 66 67 68 69 76480 5 70 71 72 73 99438 5 74 75 76 77 6697 5 78 79 80 81 22787 5 82 83 84 85 41147 5 86 87 88 89 65345 5 90 91 92 93 75531 5 94 95 96 97 90790 5 98 99 100 101 19121...
output:
1 15625 1 15625 1 15625 1 15625 1 15625 1 78125 1 62500 1 78125 1 78125 1 78125 1 78125 1 78125 2 78125 1 78125 7 234375 6 390625 1 390625 1 390625 1 390625 1 390625 2 390625 2 390625 2 390625 1 312500 1 390625 1 156250 7 781250 1 390625 1 390625 7 390625 2 390625 1 390625 1 390625 6 390625 33 390625 7 390625 1 390625 1 390625 1 390625 1 390625 1 390625 1 390625 1 390625 1 390625 2 390625 1 390625 1 390625 1 390625 1 390625 1 390625 39 781250 1 390625 1 390625 2 390625 1 390625 1 390625 1 390625...
result:
ok 93056 tokens
Test #8:
score: 10
Accepted
time: 65ms
memory: 11620kb
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 5 62 63 64 65 65133 5 66 67 68 69 74754 5 70 71 72 73 556 5 74 75 76 77 18944 5 78 79 80 81 23637 5 82 83 84 85 40316 5 86 87 88 89 56662 5 90 91 92 93 70317 5 94 95 96 97 1619 5 98 99 100 101 4018 5 ...
output:
1 12500 1 15625 1 15625 1 15625 1 15625 1 12500 1 15625 1 12500 1 12500 1 15625 1 15625 1 15625 1 12500 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 12500 1 8000 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 12500 1 12500 1 12500 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 15625 1 12500 1 15625 1 156...
result:
ok 84746 tokens
Test #9:
score: 10
Accepted
time: 75ms
memory: 11880kb
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 869 1378 2155 16920 19100 5 141 150 232 1093 15984 5 21 22 23 24 25 5 140 893 927 2366 2946 5 742 792 2198 3342 4184 5 268 305 397 920 1331 5 246 3144 4640 5217 39392 5 26 27 28 29 30 5 265 409 516 5...
output:
1 48828125 2538341 10546875000 15673 2343750000 759673 2343750000 54145169317349 3023308800000000000 1 59049 1 1048576 2003363 600000000000 790936213 3686400000000 7805087 150000000000 233 390625000 68035921 737280000000 173243 37500000000 938137 585937500 122493287 759375000000 6499 1171875000 8570089 1800000000000 1587521 63281250000 918157 21093750000 2323671073 8100000000000 2887 585937500 764120113 165888000000000 44021819 300000000000 43340471 168750000000 90354467 1537734375000 3739913851...
result:
ok 64816 tokens
Test #10:
score: 10
Accepted
time: 78ms
memory: 11808kb
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 25578 5 158 166 283 597 612 5 278 1424 4614 4642 9681 5 21 22 23 24 25 5 178 302 497 1346 2577 5 242 1138 2455 5157 7779 5 198 641 4737 5002 13183 5 147 358 796 875 3423 5 26 27 28 29 30 5 1218 1265 2499 ...
output:
1 48828125 1 48828125 191216299 675000000000 3778533703 48600000000000 214192764230063 36279705600000000000 1 59049 74674 2767921875 8222897 553584375000 1 1048576 720274069 2949120000000 1058701 42467328000 130372058357 663552000000000 45101357 409600000000 3563743 14062500000 946441 81920000000 273547 3515625000 2613230659 29524500000000 31994303 84375000000 1150619 7031250000 3188593 84375000000 14891 1757812500 4772293 2050312500000 2002121 10546875000 167555491 7680000000000 3188593 8437500...
result:
ok 64158 tokens
Extra Test:
score: 0
Extra Test Passed