QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#251008#6165. 丁香之路james1BadCreeper100 ✓216ms3888kbC++171.6kb2023-11-14 00:07:492023-11-14 00:07:49

Judging History

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

  • [2023-11-14 00:07:49]
  • 评测
  • 测评结果:100
  • 用时:216ms
  • 内存:3888kb
  • [2023-11-14 00:07:49]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long i64; 

int n, m, s, sum; 
struct edge {
    int u, v, w;
    edge(int u = 0, int v = 0, int w = 0) : u(u), v(v), w(w) {}
    bool operator< (const edge &a) const { return w < a.w; }
};
int fa[2505], bel[2505], deg[2505];
void init(void) { for (int i = 1; i <= n; ++i) fa[i] = i; }
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }

int main(void) {
    ios::sync_with_stdio(0); 
    cin >> n >> m >> s; init(); 
    for (int i = 1; i <= m; ++i) {
        int u, v; cin >> u >> v; sum += abs(u - v); 
        ++deg[u], ++deg[v]; fa[find(u)] = find(v); 
    }
    for (int i = 1; i <= n; ++i) bel[i] = find(i); 
    for (int t = 1; t <= n; ++t) {
        init(); ++deg[s]; ++deg[t]; 
        fa[find(bel[s])] = find(bel[t]); 
        i64 ans = sum, pre = 0; 
        for (int i = 1; i <= n; ++i) if (deg[i] & 1) {
            if (pre) {
                ans += i - pre;
                for (int k = pre; k < i; k++)
                    fa[find(bel[k])] = fa[find(bel[i])];
                pre = 0;
            }
            else pre = i;
        }
        vector<edge> a;
        for (int i = 1; i <= n; ++i) if (deg[i]) {
            if (pre && find(bel[i]) != find(bel[pre]))
                a.emplace_back(bel[i], bel[pre], abs(i - pre));
            pre = i;
        }
        sort(a.begin(), a.end()); 
        for (int sz = a.size(), i = 0; i < sz; ++i)
            if (find(a[i].u) != find(a[i].v)) 
                fa[find(a[i].u)] = find(a[i].v), ans += a[i].w * 2;
        cout << ans << " \n"[t == n]; --deg[s]; --deg[t]; 
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 0ms
memory: 3576kb

input:

50 9 16
14 5
36 40
9 29
21 4
42 46
9 30
41 17
37 33
16 13

output:

139 138 137 136 137 136 135 134 133 132 131 130 129 130 129 128 127 128 129 130 131 130 129 128 127 126 125 124 123 124 125 126 127 128 129 130 129 130 131 132 133 132 131 130 129 128 129 130 131 132

result:

ok 50 numbers

Test #2:

score: 5
Accepted
time: 0ms
memory: 3884kb

input:

50 9 38
11 7
13 33
22 34
11 36
37 16
39 1
14 18
18 26
37 46

output:

163 164 165 166 167 168 169 168 167 166 165 164 163 164 165 166 165 164 165 166 167 168 167 166 165 164 165 166 167 168 169 170 171 170 171 172 171 172 171 170 169 168 167 166 165 164 165 166 167 168

result:

ok 50 numbers

Test #3:

score: 5
Accepted
time: 0ms
memory: 3800kb

input:

50 9 4
44 21
35 32
20 30
12 50
27 49
40 7
42 3
11 38
50 42

output:

229 228 227 228 227 226 225 226 227 228 229 230 231 232 233 234 235 236 237 236 235 236 237 238 239 240 241 242 241 240 239 238 237 236 235 236 237 236 235 234 235 236 237 236 235 234 233 232 231 232

result:

ok 50 numbers

Test #4:

score: 5
Accepted
time: 0ms
memory: 3640kb

input:

50 15 17
50 32
9 32
11 39
50 13
26 33
6 11
12 13
18 29
10 46
9 16
37 32
27 5
44 29
44 3
12 35

output:

300 299 298 299 300 299 300 301 302 303 302 301 300 299 298 297 298 297 298 299 300 301 302 303 304 305 304 305 306 307 308 309 308 309 310 309 308 309 310 309 308 307 306 305 304 303 304 305 306 307

result:

ok 50 numbers

Test #5:

score: 5
Accepted
time: 0ms
memory: 3636kb

input:

50 15 7
15 44
43 10
1 3
33 22
5 38
21 23
48 23
12 30
38 13
12 48
41 49
18 11
15 47
49 36
39 41

output:

306 307 308 309 310 311 312 311 310 309 310 309 310 311 310 311 312 311 310 309 308 309 308 307 306 305 304 303 302 301 302 303 304 305 304 303 304 305 306 305 304 303 302 303 302 301 300 299 300 301

result:

ok 50 numbers

Test #6:

score: 5
Accepted
time: 0ms
memory: 3572kb

input:

50 15 28
21 26
9 1
12 1
48 3
36 14
26 41
30 29
23 2
31 35
2 45
49 3
5 32
23 44
26 48
38 47

output:

327 328 329 328 327 328 329 330 329 328 327 326 327 328 329 328 327 326 325 324 323 324 323 324 325 326 327 326 325 324 323 322 323 324 325 324 325 324 323 322 321 322 323 324 323 324 325 324 323 324

result:

ok 50 numbers

Test #7:

score: 5
Accepted
time: 0ms
memory: 3876kb

input:

50 802 36
41 13
42 10
41 23
22 19
46 12
35 41
42 20
21 6
8 5
13 32
35 15
33 3
14 31
38 40
15 30
37 13
24 14
25 15
15 4
39 11
3 2
27 1
25 49
30 14
19 39
20 32
47 40
19 13
28 32
8 38
7 22
41 24
46 23
44 3
18 10
33 34
40 35
21 15
47 22
8 12
7 44
44 25
33 4
38 35
12 50
45 28
48 50
38 5
37 16
26 23
48 8
...

output:

13775 13776 13775 13776 13775 13776 13775 13774 13775 13776 13777 13776 13777 13776 13775 13776 13777 13776 13775 13776 13777 13776 13775 13774 13775 13774 13775 13776 13777 13778 13779 13780 13781 13780 13781 13782 13781 13782 13781 13780 13781 13780 13781 13780 13779 13780 13781 13780 13779 13778

result:

ok 50 numbers

Test #8:

score: 5
Accepted
time: 1ms
memory: 3680kb

input:

50 280 43
47 35
38 1
22 44
41 23
37 20
34 35
23 26
46 3
36 34
27 2
1 11
20 48
25 43
39 32
48 37
31 8
45 35
6 7
26 32
45 48
24 14
15 11
42 26
16 25
7 28
13 20
6 44
35 36
42 41
41 39
47 12
4 10
19 50
8 15
34 19
42 36
24 39
16 44
9 3
40 10
13 48
3 40
32 48
7 5
21 37
20 19
32 35
41 24
47 37
49 48
7 22
2...

output:

4320 4319 4320 4321 4322 4321 4320 4319 4318 4319 4318 4319 4318 4317 4316 4317 4318 4319 4318 4317 4318 4319 4318 4317 4316 4315 4314 4315 4316 4317 4318 4317 4316 4315 4314 4315 4316 4315 4314 4315 4316 4317 4316 4317 4316 4317 4316 4315 4316 4315

result:

ok 50 numbers

Test #9:

score: 5
Accepted
time: 1ms
memory: 3580kb

input:

300 5407 16
67 248
32 54
103 291
234 158
42 294
80 125
25 217
118 142
154 2
156 290
213 234
144 116
54 92
237 276
240 56
59 131
81 146
189 81
8 142
102 295
31 233
51 112
125 201
199 269
296 137
224 177
222 11
276 61
297 208
210 124
10 97
134 55
284 13
195 39
13 20
67 80
178 85
102 182
18 225
107 268...

output:

536303 536304 536305 536306 536307 536308 536309 536308 536309 536308 536307 536308 536309 536308 536307 536308 536309 536308 536309 536310 536309 536310 536311 536312 536313 536314 536313 536314 536315 536316 536317 536316 536317 536318 536317 536318 536319 536320 536321 536320 536321 536320 536321...

result:

ok 300 numbers

Test #10:

score: 5
Accepted
time: 1ms
memory: 3612kb

input:

300 1744 24
88 147
272 42
95 101
154 2
29 44
70 246
272 185
201 101
276 78
265 110
103 122
52 98
241 31
131 200
250 208
276 172
279 177
34 289
38 119
117 17
65 11
50 234
253 28
83 14
77 95
276 196
261 296
245 179
19 209
185 6
184 144
116 125
63 114
140 103
290 1
255 273
201 23
26 74
191 286
127 299
...

output:

175723 175724 175723 175722 175721 175722 175721 175720 175721 175722 175721 175722 175723 175722 175721 175720 175721 175720 175719 175718 175717 175716 175717 175718 175719 175718 175717 175718 175717 175716 175717 175718 175719 175720 175721 175720 175721 175720 175721 175720 175721 175722 175723...

result:

ok 300 numbers

Test #11:

score: 5
Accepted
time: 4ms
memory: 3544kb

input:

1600 0 290

output:

289 288 287 286 285 284 283 282 281 280 279 278 277 276 275 274 273 272 271 270 269 268 267 266 265 264 263 262 261 260 259 258 257 256 255 254 253 252 251 250 249 248 247 246 245 244 243 242 241 240 239 238 237 236 235 234 233 232 231 230 229 228 227 226 225 224 223 222 221 220 219 218 217 216 215 ...

result:

ok 1600 numbers

Test #12:

score: 5
Accepted
time: 5ms
memory: 3768kb

input:

1600 1 637
871 768

output:

1104 1103 1102 1101 1100 1099 1098 1097 1096 1095 1094 1093 1092 1091 1090 1089 1088 1087 1086 1085 1084 1083 1082 1081 1080 1079 1078 1077 1076 1075 1074 1073 1072 1071 1070 1069 1068 1067 1066 1065 1064 1063 1062 1061 1060 1059 1058 1057 1056 1055 1054 1053 1052 1051 1050 1049 1048 1047 1046 1045 ...

result:

ok 1600 numbers

Test #13:

score: 5
Accepted
time: 6ms
memory: 3528kb

input:

1600 1 1573
970 768

output:

1572 1571 1570 1569 1568 1567 1566 1565 1564 1563 1562 1561 1560 1559 1558 1557 1556 1555 1554 1553 1552 1551 1550 1549 1548 1547 1546 1545 1544 1543 1542 1541 1540 1539 1538 1537 1536 1535 1534 1533 1532 1531 1530 1529 1528 1527 1526 1525 1524 1523 1522 1521 1520 1519 1518 1517 1516 1515 1514 1513 ...

result:

ok 1600 numbers

Test #14:

score: 5
Accepted
time: 5ms
memory: 3596kb

input:

1600 1 471
883 1359

output:

2246 2245 2244 2243 2242 2241 2240 2239 2238 2237 2236 2235 2234 2233 2232 2231 2230 2229 2228 2227 2226 2225 2224 2223 2222 2221 2220 2219 2218 2217 2216 2215 2214 2213 2212 2211 2210 2209 2208 2207 2206 2205 2204 2203 2202 2201 2200 2199 2198 2197 2196 2195 2194 2193 2192 2191 2190 2189 2188 2187 ...

result:

ok 1600 numbers

Test #15:

score: 5
Accepted
time: 20ms
memory: 3600kb

input:

1600 119794 1220
1580 340
1248 917
976 168
425 438
139 1344
634 1032
856 1006
376 760
1001 267
344 1538
927 535
1169 771
143 36
1176 33
468 1224
807 125
1199 1359
1035 166
719 1425
1012 1421
4 1450
1053 1457
816 656
302 895
1081 356
929 983
1600 1204
1397 1218
184 26
1505 1284
1473 530
527 499
1466 ...

output:

63827859 63827860 63827861 63827860 63827859 63827860 63827859 63827858 63827859 63827858 63827859 63827858 63827857 63827858 63827857 63827856 63827855 63827856 63827857 63827858 63827857 63827856 63827855 63827854 63827853 63827852 63827851 63827852 63827851 63827852 63827851 63827850 63827849 638...

result:

ok 1600 numbers

Test #16:

score: 5
Accepted
time: 14ms
memory: 3604kb

input:

1600 20557 1345
251 887
1298 1046
359 1344
1521 627
345 510
1285 624
592 841
1273 1478
166 1440
1386 879
1152 171
671 397
1190 1463
1580 235
620 1067
532 197
1339 703
1433 1378
1486 258
864 541
150 1344
600 1523
1210 320
877 1017
554 300
458 409
1548 408
1162 47
169 970
1399 916
1236 1436
1451 54
15...

output:

10982798 10982799 10982798 10982799 10982798 10982799 10982800 10982801 10982802 10982801 10982800 10982801 10982800 10982799 10982800 10982801 10982802 10982801 10982802 10982803 10982804 10982805 10982804 10982803 10982804 10982803 10982804 10982803 10982804 10982803 10982804 10982803 10982804 109...

result:

ok 1600 numbers

Test #17:

score: 5
Accepted
time: 13ms
memory: 3700kb

input:

1600 506 255
270 1297
762 532
742 1589
540 1269
1003 416
1480 339
1217 777
421 1472
1093 315
1429 1153
1008 1024
1438 484
754 1224
161 693
1111 1587
744 961
156 1257
148 1342
529 1492
573 908
1590 1362
699 758
190 1581
1381 543
230 1383
1340 318
462 848
825 1075
1302 1583
672 396
612 1046
511 414
8 ...

output:

274434 274433 274432 274433 274434 274433 274432 274433 274434 274435 274436 274435 274434 274433 274432 274431 274430 274429 274428 274427 274426 274427 274428 274429 274428 274429 274428 274429 274430 274431 274430 274431 274432 274431 274430 274429 274430 274431 274430 274431 274432 274431 274430...

result:

ok 1600 numbers

Test #18:

score: 5
Accepted
time: 216ms
memory: 3696kb

input:

2500 1998692 830
1760 65
1891 877
1838 868
259 938
2025 163
496 1314
2022 1845
1132 1407
2404 1374
44 1347
1657 2300
228 412
1685 96
2466 617
359 1062
753 1567
424 521
1950 28
2003 517
421 1615
968 1478
2251 1106
2098 2440
965 1922
1378 657
75 400
1375 1867
22 761
1512 1667
1582 2335
1735 687
2382 3...

output:

1665236581 1665236582 1665236583 1665236582 1665236581 1665236582 1665236583 1665236582 1665236583 1665236582 1665236581 1665236582 1665236581 1665236582 1665236581 1665236580 1665236579 1665236578 1665236577 1665236576 1665236577 1665236578 1665236579 1665236578 1665236579 1665236578 1665236579 166...

result:

ok 2500 numbers

Test #19:

score: 5
Accepted
time: 34ms
memory: 3568kb

input:

2500 39989 2291
1945 1757
766 1978
2372 1645
634 1032
1614 911
1402 1849
1966 2268
615 1760
961 2009
825 166
1800 1034
661 520
1913 647
117 900
1166 559
1043 1524
2260 1772
743 1037
324 1521
1596 1379
201 1214
388 386
1614 331
1409 760
1379 950
256 820
657 216
1542 375
2111 2105
2087 1739
147 586
12...

output:

33461730 33461729 33461728 33461729 33461728 33461729 33461728 33461727 33461728 33461727 33461726 33461727 33461726 33461725 33461724 33461723 33461722 33461721 33461720 33461719 33461720 33461721 33461720 33461721 33461722 33461721 33461720 33461719 33461720 33461719 33461720 33461719 33461718 334...

result:

ok 2500 numbers

Test #20:

score: 5
Accepted
time: 40ms
memory: 3888kb

input:

2500 6254 705
2086 1956
687 1030
651 2100
415 1047
909 1032
1412 629
802 351
808 1076
2051 2037
1437 119
926 1328
763 2046
1513 2085
109 32
2474 831
1712 145
2006 2115
487 1639
1787 2128
2472 1608
2353 251
1312 1602
2283 390
2122 1544
1326 1127
549 2286
2104 686
2348 457
640 1077
1246 309
1261 2196
...

output:

5197468 5197467 5197468 5197469 5197468 5197469 5197468 5197467 5197466 5197467 5197466 5197465 5197464 5197463 5197462 5197461 5197462 5197461 5197460 5197461 5197460 5197459 5197458 5197457 5197458 5197457 5197456 5197455 5197456 5197455 5197456 5197455 5197456 5197457 5197456 5197457 5197458 5197...

result:

ok 2500 numbers

Extra Test:

score: 0
Extra Test Passed