QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#99703#6267. Triples of CowsScintilla15 202ms44624kbC++142.3kb2023-04-23 15:19:012023-04-23 15:19:05

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-23 15:19:05]
  • 评测
  • 测评结果:15
  • 用时:202ms
  • 内存:44624kb
  • [2023-04-23 15:19:01]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define drep(i, s, e) for (int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define pv(a) cout << #a << " = " << a << endl
#define pa(a, l, r) cout << #a " : "; rep(_, l, r) cout << a[_] << ' '; cout << endl

const int N = 4e5 + 10;

int read() {
  int x = 0, f = 1; char c = getchar();
  for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
  return x * f;
}

int n, p[N], f[N], g[N], ans;
vector <int> e[N];

int fa[N], sz[N];

int get(int u) {
  return u == fa[u] ? u : fa[u] = get(fa[u]);
}

void merge(int u, int v) {
  fa[get(v)] = get(u);
}

int d3(int x) {
  return (x + 1) * x * (x - 1);
} ;

void del(int u) {
  for (int x : e[u]) ans -= d3(f[get(x)]);
  int r = get(p[u]);
  -- f[r], g[r] -= f[u];
  -- f[p[r]], g[p[r]] -= (f[r] + 1) * (f[r] + 1) - f[r] * f[r];
  if (p[r] < n) -- g[p[p[r]]];
  ans -= 2 * (f[r] + 1) * f[u] + f[u] * f[u] - g[u];
  ans -= 2 * g[r];
  ans -= 2 * ((f[p[r]] - f[r]) + f[p[p[r]]]);
  for (int x : e[u]) if (get(x) != r) {
    int v = get(x);
    ans -= 2 * g[v];
    ans += 2 * (f[r] + 1) * g[v];
    ans += 2 * g[r] * f[v];
    ans += 2 * f[v] * ((f[p[r]] - f[r]) + f[p[p[r]]]);
  }
  for (int x : e[u]) if (get(x) != r) {
    int v = get(x);
    f[r] += f[v], g[r] += g[v];
    f[p[r]] += f[v], g[p[r]] += f[r] * f[r] - (f[r] - f[v]) * (f[r] - f[v]);
    merge(r, v);
  }
  ans += d3(f[r]);
}

void dfs0(int u, int fa) {
  p[u] = fa;
  for (int v : e[u]) if (v != fa) {
    dfs0(v, u);
    if (u <= n) f[u] += f[v], g[u] += f[v] * f[v];
    else ++ f[u], g[u] += f[v];
  }
}

signed main() {
  n = read();
  rep(i, 1, n - 1) {
    int u = read(), v = read();
    e[u].emplace_back(n + i), e[n + i].emplace_back(u);
    e[v].emplace_back(n + i), e[n + i].emplace_back(v);
  }
  dfs0(n, 0);
  rep(i, 1, n - 1) ans += 2 * f[p[i]] * f[i];
  rep(i, 1, n) ans += f[i] * f[i] - g[i];
  rep(i, n + 1, n + n - 1) ans += d3(f[i]);
  rep(i, 1, n + n - 1) fa[i] = i;
  rep(i, 1, n) {
    printf("%lld\n", ans);
    if (i < n) del(i);
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1 2
2 3

output:

2
0
0

result:

ok 3 lines

Test #2:

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

input:

4
1 2
1 3
1 4

output:

6
6
0
0

result:

ok 4 lines

Test #3:

score: 5
Accepted
time: 2ms
memory: 22068kb

input:

5
3 5
5 1
1 4
1 2

output:

8
10
2
0
0

result:

ok 5 lines

Test #4:

score: 0
Wrong Answer
time: 7ms
memory: 20136kb

input:

500
11 3
327 355
314 180
428 417
349 438
319 16
322 365
430 4
116 384
95 469
476 16
96 444
330 323
282 380
179 365
416 151
361 34
422 417
122 440
206 264
169 381
237 420
167 47
118 421
442 149
474 112
135 359
230 221
178 391
39 464
326 105
198 24
33 419
455 240
120 50
406 134
124 32
186 424
6 157
21...

output:

1970
1960
1958
1956
2020
2016
2014
2012
2010
2008
2004
2002
1998
1996
1992
1990
2022
2026
2036
2020
2012
2004
2002
2000
2002
1992
1990
1992
1990
1988
1986
1984
1994
1992
2012
2004
2002
2022
2020
2016
2014
2020
2018
2022
2020
2018
2028
2034
2030
2040
2064
2062
2038
2030
2028
2022
2014
2010
2008
2002
...

result:

wrong answer 5th lines differ - expected: '2050', found: '2020'

Test #5:

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

input:

500
117 273
162 26
468 332
44 21
227 163
368 215
241 403
60 319
297 303
376 139
14 134
438 452
8 65
195 48
230 188
475 485
152 136
35 375
272 487
72 242
208 180
330 157
75 487
278 159
110 497
364 339
255 73
405 16
463 368
26 320
226 377
149 410
240 436
439 56
43 422
37 287
186 228
347 248
294 435
67...

output:

1952
1950
1942
1932
1934
1928
1920
1914
1912
1910
1908
1906
1904
1898
1892
1924
1994
1984
2090
2086
2084
2104
2102
2100
2098
2096
2102
2154
2150
2138
2136
2146
2144
2188
2194
2192
2200
2198
2194
2192
2186
2184
2182
2198
2196
2194
2198
2202
2212
2210
2206
2202
2200
2194
2200
2190
2254
2250
2304
2302
...

result:

wrong answer 16th lines differ - expected: '1932', found: '1924'

Test #6:

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

input:

5000
192 2280
866 1993
3318 2270
866 4634
1062 1191
1616 1183
3798 951
866 1590
4607 3400
866 4962
1816 4504
468 325
4569 1736
866 1130
2690 866
4389 866
4240 1120
1932 1614
2487 3373
866 1903
1261 2826
219 1064
44 4360
866 1333
866 1636
2726 2577
2130 866
4693 4818
1190 866
3319 2069
1424 240
1113 ...

output:

4926576
4926574
4926572
4926566
4926564
4926560
4926554
4922120
4922118
4917686
4917684
4917680
4913250
4908822
4908820
4904394
4904356
4904380
4904378
4904376
4904374
4904372
4904370
4899946
4899962
4895540
4895538
4891118
4886700
4886698
4886696
4882280
4877866
4877864
4877862
4877860
4873448
4869...

result:

wrong answer 25th lines differ - expected: '4899970', found: '4899962'

Test #7:

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

input:

5000
1026 19
4489 1374
1374 976
2917 317
2875 19
3741 2419
3056 444
19 1591
1983 19
4825 1374
2444 1374
2937 19
1374 2301
1246 1374
19 4829
19 3893
1374 3084
19 2482
19 3772
19 2434
4565 2642
3810 3291
1650 4033
1374 3824
4103 3281
19 852
19 2561
1018 112
1374 2096
1661 1374
19 280
19 3695
356 2671
...

output:

7126950
7122520
7118092
7118090
7113664
7113652
7113650
7110676
7107704
7103280
7100310
7095888
7091468
7088500
7084082
7079666
7075252
7070840
7066430
10708394476
10708394474
10708394480
10693828192
10679275122
10664735264
10664732298
10650205646
10650205644
10650205642
10635692190
10635689226
1062...

result:

wrong answer 20th lines differ - expected: '10708504626', found: '10708394476'

Test #8:

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

input:

5000
3656 2617
1546 2617
3883 2531
487 302
2617 1655
2617 3150
684 4158
2641 4762
2552 2300
2617 2415
3766 1485
3401 155
2458 2617
1941 1219
2617 4612
990 4670
4551 1784
2617 3315
2617 3058
2617 4611
3379 2555
1745 1914
2617 4652
3820 1368
557 4236
4777 2667
774 4214
4592 961
3468 754
539 3369
2390 ...

output:

5011042
5006584
5006580
5006538
5002082
5002074
4997620
4997618
4997612
4997616
4997614
4993162
4988712
4988710
4988708
4988802
4984354
4984072
4984068
4979622
4975178
4970736
4970732
4970730
4970728
4970724
4966284
4961846
4961866
4957430
4952996
4948564
4948560
4948550
4944120
4939692
4939690
4935...

result:

wrong answer 10th lines differ - expected: '4997618', found: '4997616'

Test #9:

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

input:

5000
1963 1714
2089 1714
1958 1714
1174 516
2468 1714
4013 780
542 1714
1714 921
1714 494
2799 3447
1714 4167
2663 1377
4753 58
3643 4557
1714 623
1714 2198
4997 1992
1518 722
1714 1367
2723 4870
4103 2072
1714 4384
4299 2533
433 969
1714 4644
1253 1652
4838 2735
1508 1714
596 4817
2465 3850
3287 23...

output:

5108150
5103636
5099124
5099122
5099116
5099086
5099084
5099076
5094566
5094564
5094562
5094560
5094556
5090048
5085542
5081038
5076536
5076532
5076490
5071990
5067492
5067490
5062994
5058500
5054008
5049518
5049516
5049514
5045026
5045050
5045048
5040562
5040594
5036110
5036108
5031626
5027146
5022...

result:

wrong answer 30th lines differ - expected: '5045066', found: '5045050'

Test #10:

score: 0
Wrong Answer
time: 4ms
memory: 22320kb

input:

5000
1952 4980
1776 4362
3887 1033
1033 4047
523 4980
357 1033
1033 941
4631 1033
1033 3253
960 4980
1033 2582
4980 887
984 2694
3715 4956
4728 1376
4980 3197
2996 4357
1490 1033
1033 2798
9 1033
4980 1084
1033 3349
2554 4980
204 1037
1033 4660
3004 1249
3817 2960
1033 1761
1033 2152
1033 1740
1033 ...

output:

7200814
7197878
7193392
7190458
7190456
7187524
7183040
7178558
7175628
7171148
7168220
7163742
7159266
7154792
7151866
7147394
7147226
7142756
7138288
7133822
7130898
7126434
7126428
7121966
7117506
7113048
7108592
7108594
7105672
7101218
7096766
7092316
7087868
7087866
7087864
7087862
7084942
7080...

result:

wrong answer 28th lines differ - expected: '7108598', found: '7108594'

Test #11:

score: 0
Wrong Answer
time: 202ms
memory: 44624kb

input:

200000
180343 93112
133794 25463
15259 32390
161405 75514
53906 75514
31334 75514
145757 75514
91720 75514
113316 10952
75514 24136
30812 144626
84587 109632
28810 104546
75514 162784
73000 185642
75514 12153
75514 30841
74493 76012
177125 150153
100571 107545
118366 139210
10965 75514
21955 75514
7...

output:

7907948828
7907771022
7907771020
7907771018
7907771016
7907593212
7907593202
7907593200
7907593198
7907593196
7907593194
7907593192
7907593194
7907593192
7907415390
7907237590
7907059792
7907059576
7907059584
7907059582
7906881786
7906881784
7906703990
7906526198
7906526196
7906348406
7906170618
790...

result:

wrong answer 13th lines differ - expected: '7907593200', found: '7907593194'

Test #12:

score: 0
Wrong Answer
time: 166ms
memory: 40064kb

input:

200000
156524 164378
63451 181093
142236 156524
156524 91309
195366 63451
63451 54126
62067 43431
48083 17306
156524 139870
156524 79853
63451 118039
63451 10162
116377 114109
82955 48083
17725 63451
1075 156524
77519 156524
156524 118428
63451 126448
108533 156524
133574 156524
63451 10239
119214 1...

output:

11749107100
11748929116
11748810644
11748774978
11748774704
11748656234
11748537766
11748419300
11748300836
11748300562
11748122580
11747944600
11747826138
11747648160
11747470184
11747292210
11747173750
11746995778
11746817808
11746699350
11746521382
11746343416
11746343414
11746165450
11748102948
...

result:

wrong answer 100th lines differ - expected: '11739742684', found: '11739742644'

Test #13:

score: 0
Wrong Answer
time: 142ms
memory: 41772kb

input:

200000
128878 43530
11660 61275
93778 135514
128878 65607
105027 128878
99196 126852
121316 119378
12994 121964
128878 157185
186752 128878
66811 97145
166913 95469
188773 91487
128878 164320
52546 128878
173916 128878
180121 126852
174374 128878
123398 126852
123003 128878
109982 128878
106656 1288...

output:

11440362682
11440184680
11440006680
11439828682
11439650686
11439472692
11439354062
11439176070
11439176068
11439176066
11439057438
11438879448
11438701460
11438523474
11438345490
11438167508
11438167506
11437989526
11437989516
11437811538
11437633562
11437455588
11437455584
11437336958
11437158986
...

result:

wrong answer 28th lines differ - expected: '11436862562', found: '11436862522'

Test #14:

score: 0
Wrong Answer
time: 117ms
memory: 40540kb

input:

200000
75292 57657
154653 141350
140800 57657
57657 162746
124811 59959
154653 89884
57657 25957
60896 67370
183207 26852
57657 43172
188291 57657
154653 102124
57657 157547
132684 57657
154653 143124
124811 188592
57657 109286
66896 87163
57657 30111
154653 131248
107225 57657
139132 29848
181221 1...

output:

11764531042
11764353072
11764175104
11763997138
11763878524
11763759912
11763641302
11763634162
11763515554
11763337590
11763159628
11762981668
11762803710
11762685104
11762507148
11762388544
11762353088
11762175134
11761997182
11761878580
11761700630
11761665176
11761487228
11761309282
11761131338
...

result:

wrong answer 99th lines differ - expected: '11753076568', found: '11753076566'

Test #15:

score: 0
Wrong Answer
time: 185ms
memory: 39316kb

input:

200000
48508 52931
115469 53334
53334 109332
55615 111128
160153 129069
81733 149640
69172 127972
53334 71755
107633 53334
92200 144859
191346 61711
192310 131522
144360 89737
112809 69429
24034 53334
8244 53334
134631 53334
53334 157868
179139 39842
112773 53334
131063 78546
95501 143642
50916 5333...

output:

7974890890
7974712844
7974534800
7974356758
7974178718
7974000680
7973822644
7973644610
7973632734
7973454702
7973454700
7973276670
7973098642
7973091582
7973079708
7973079706
7973079702
7973079832
7973072774
7972894748
7972894742
7972894738
7972716714
7972716702
7972538680
7972360660
7972182642
797...

result:

wrong answer 18th lines differ - expected: '7973079888', found: '7973079832'

Test #16:

score: 0
Wrong Answer
time: 179ms
memory: 41288kb

input:

200000
189585 140451
189585 21397
97507 124392
189551 66778
35172 110107
34572 137133
189585 175319
68631 185609
189585 113509
195998 52967
125268 189585
189585 38545
195154 62941
22458 189585
111738 150491
181476 40967
189585 175600
183092 164108
2191 91624
189585 98869
104639 189585
189585 11160
1...

output:

7948844896
7948844894
7948666996
7948667048
7948489152
7948311258
7948133366
7948121538
7948121536
7947943646
7947943854
7947943852
7947765964
7947588078
7947588076
7947588074
7947410190
7947232308
7947054428
7946876550
7946698674
7946698672
7946520798
7946342926
7946342924
7946165054
7946165046
794...

result:

wrong answer 4th lines differ - expected: '7948667060', found: '7948667048'

Test #17:

score: 0
Wrong Answer
time: 193ms
memory: 40332kb

input:

200000
52744 169423
21958 49886
107574 14898
179360 193309
52744 173255
11649 194058
52744 37299
185040 52744
173083 16183
45172 52744
111564 52744
118979 40378
16515 40367
116092 15886
21781 52744
52744 18485
155320 52744
164746 118979
52744 178385
119944 52744
183596 148338
97026 100365
154834 159...

output:

7949417986
7949414460
7949414456
7949236732
7949059010
7948881290
7948881330
7948703612
7948525896
7948525894
7948348180
7948170468
7948170480
7948163370
7947985660
7947985422
7947807714
7947807828
7947807824
7947630118
7947452414
7947452412
7947274710
7947097010
7947097022
7947097020
7947097016
794...

result:

wrong answer 7th lines differ - expected: '7948881350', found: '7948881330'

Test #18:

score: 0
Wrong Answer
time: 185ms
memory: 44564kb

input:

200000
98188 97568
97568 139023
97568 145232
43972 86482
97568 76922
152654 113293
97568 187093
14560 97568
130417 25367
180256 26394
70931 175568
97568 46170
102988 88140
152897 80698
151625 97568
28288 28935
97568 184813
46246 97568
126910 118530
120407 37832
97568 130045
101579 48512
176793 92123...

output:

7947926838
7947926846
7947926844
7947926872
7947926870
7947748764
7947570660
7947570658
7947392556
7947392554
7947392552
7947392550
7947392548
7947392546
7947214446
7947214444
7947214442
7947214440
7947214438
7947036340
7947029280
7946851184
7946673090
7946494998
7946494996
7946494994
7946494992
794...

result:

wrong answer 2nd lines differ - expected: '7947926848', found: '7947926846'

Test #19:

score: 0
Wrong Answer
time: 187ms
memory: 40972kb

input:

200000
82514 160608
129118 74477
117781 160275
32607 77450
33384 83542
177617 190138
33384 6337
94051 17548
75494 139091
22526 33384
194668 33384
9010 33384
32463 33384
33384 81726
33384 199774
68788 33384
52181 175598
18372 33384
160069 33384
75532 3294
154793 166505
33384 84585
52141 162634
138451...

output:

7901247652
7901247650
7901069904
7901069902
7901069898
7900892154
7900714412
7900714410
7900714408
7900536668
7900536666
7900358928
7900181192
7900181188
7900003454
7899825722
7899825720
7899647990
7899648006
7899470278
7899468520
7899468522
7899290796
7899290794
7899290792
7899290790
7899290788
789...

result:

wrong answer 19th lines differ - expected: '7899648012', found: '7899648006'

Test #20:

score: 0
Wrong Answer
time: 175ms
memory: 41200kb

input:

200000
123057 85473
181057 139168
139374 155981
97580 66941
139374 26235
92577 28176
53567 44615
139374 158256
139374 111698
139374 7486
167825 194890
39334 139374
124253 139374
99441 512
41950 157947
45135 122712
19652 139374
145589 139374
77187 106020
111608 128762
139374 163048
67917 139374
51654...

output:

7939722716
7939722714
7939722720
7939544578
7939544568
7939544566
7939544554
7939544724
7939544686
7939544684
7939366544
7939366542
7939188404
7939010268
7938832134
7938654002
7938654000
7938475870
7938475858
7938297730
7938119604
7938119750
7937941626
7937763504
7937763490
7937585370
7937585368
793...

result:

wrong answer 3rd lines differ - expected: '7939722724', found: '7939722720'