QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#670941#9230. Routing K-Codes11d10xyWA 63ms24244kbC++141.4kb2024-10-24 08:57:372024-10-24 08:57:38

Judging History

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

  • [2024-10-24 08:57:38]
  • 评测
  • 测评结果:WA
  • 用时:63ms
  • 内存:24244kb
  • [2024-10-24 08:57:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using u64=unsigned long long;
int n,m,rt;u64 ans=-1ull;
struct N_{int d;u64 s1,s2;}f[200010],g[200010];
vector<int>G[200010];
inline N_ merge1(N_ x){
   return{x.d+1,x.s1*2+1,x.s2};
}
inline N_ merge2(N_ x,N_ y){
   return{max(x.d,y.d)+1,(x.s1+y.s1)*2+1,x.s2+y.s2+min(x.s1,y.s1)};
}
void dfs(int u,int fa){
   if(fa)G[u].erase(find(begin(G[u]),end(G[u]),fa));
   for(int v:G[u])dfs(v,u);
   if(G[u].empty())f[u]={0,1,0};
   else if(G[u].size()==1)f[u]=merge1(f[G[u][0]]);
   else f[u]=merge2(f[G[u][0]],f[G[u][1]]);
}
void dfs2(int u){
   if(G[u].size()==1){
      int v=G[u][0];
      g[v]=merge1(g[u]),dfs2(v);
   }else if(G[u].size()==2){
      int x=G[u][0],y=G[u][1];
      g[x]=merge2(g[u],f[y]),
      g[y]=merge2(g[u],f[x]);
      dfs2(x),dfs2(y);
   }
   if(u==rt){
      if(f[u].d<32)ans=min(ans,f[u].s2+f[u].s1);
   }else{
      if(G[u].empty()&&g[u].d<32)ans=min(ans,g[u].s2+g[u].s1);
      if(G[u].size()==1){
         N_ w=merge2(g[u],f[G[u][0]]);
         if(w.d<32)ans=min(ans,w.s1+w.s2);
      }
   }
}
int main(){
   scanf("%d%d",&n,&m);
   if(n==1)return puts("0"),0;
   if(m!=n-1)return puts("NIE"),0;
   for(int u,v;m--;){
      scanf("%d%d",&u,&v);
      G[u].push_back(v),G[v].push_back(u);
   }
   for(int i=1;i<=n;i++)if(G[i].size()==1)rt=i;
   dfs(rt,0),g[rt]={-1,0,0},dfs2(rt);
   if(ans!=-1ull)printf("%llu",ans);
   else printf("NIE");
   return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 12044kb

input:

4 3
1 2
1 3
1 4

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 1ms
memory: 8396kb

input:

4 6
1 2
2 3
3 4
4 1
1 3
2 4

output:

NIE

result:

ok single line: 'NIE'

Test #3:

score: 0
Accepted
time: 1ms
memory: 8728kb

input:

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

output:

NIE

result:

ok single line: 'NIE'

Test #4:

score: 0
Accepted
time: 56ms
memory: 24036kb

input:

200000 199999
172774 188052
195063 155577
38023 148303
30605 155047
170238 19344
46835 58255
154268 109062
197059 116041
136424 12058
42062 149807
109545 115380
132322 51106
16706 162612
62234 31319
195735 80435
173898 84051
19876 102910
186924 9136
123094 117097
145054 173049
137364 152731
82662 18...

output:

NIE

result:

ok single line: 'NIE'

Test #5:

score: 0
Accepted
time: 58ms
memory: 24052kb

input:

200000 199999
168192 30733
164413 46673
175210 2329
69389 67102
33991 152553
91061 55265
166724 117726
90148 157176
34831 12213
60756 105488
121891 155192
82202 155666
102083 156661
38968 75200
190004 107321
72436 92732
64314 65004
39210 91106
70455 173568
179742 29844
126232 19552
133509 110602
131...

output:

20980030044349

result:

ok single line: '20980030044349'

Test #6:

score: 0
Accepted
time: 0ms
memory: 11552kb

input:

4 3
1 2
1 3
1 4

output:

6

result:

ok single line: '6'

Test #7:

score: 0
Accepted
time: 55ms
memory: 24060kb

input:

199021 199020
189105 111001
147300 187047
67395 102319
25317 152109
56495 115535
11656 19974
119178 6528
84571 159100
198873 156684
21161 163040
91720 165273
168305 140152
104884 119802
131 177991
35930 74934
27528 278
177640 162738
118439 69472
20365 85043
184995 54207
64542 188847
97881 167717
188...

output:

NIE

result:

ok single line: 'NIE'

Test #8:

score: 0
Accepted
time: 51ms
memory: 24092kb

input:

200000 199999
145608 31176
94180 155303
112924 85699
196865 176102
34049 30841
84924 191665
164317 97582
10102 125492
114493 20622
127660 194591
183851 21461
167689 53839
59189 126425
135853 79950
173910 4196
8134 182272
42157 63799
5109 182005
197391 154014
93467 130380
1508 66644
129681 199910
677...

output:

25146839515965

result:

ok single line: '25146839515965'

Test #9:

score: 0
Accepted
time: 57ms
memory: 24104kb

input:

200000 199999
160386 189041
24452 73297
75992 87415
87012 116413
18645 2219
151007 100916
87623 77520
51217 45179
51633 67938
183428 99891
74684 129965
186795 70345
28743 22633
107782 28087
117185 78477
46846 176763
18968 80952
118201 35872
123906 140127
65784 66684
24802 134847
42591 150517
27123 1...

output:

9894117829832

result:

ok single line: '9894117829832'

Test #10:

score: 0
Accepted
time: 53ms
memory: 24116kb

input:

200000 199999
42958 26294
73743 94861
161036 525
22581 6649
152064 106483
126795 178801
147721 107972
43433 197974
75281 163319
170596 167054
180443 168322
1443 163261
197722 164837
144573 16585
6005 143774
195029 188032
112864 105465
108330 154314
138435 103667
66734 146178
15416 123293
22322 10216...

output:

28756428378750

result:

ok single line: '28756428378750'

Test #11:

score: 0
Accepted
time: 2ms
memory: 9788kb

input:

199000 199099
149311 147296
89797 115798
124184 88539
170531 79689
134688 98182
53272 56612
68205 106798
156914 76119
158177 131
29557 179794
35380 78679
72756 116830
122836 23339
33434 147647
193860 131424
52240 110141
166223 94852
47072 83029
156709 75295
184679 174874
52901 95437
137870 130531
58...

output:

NIE

result:

ok single line: 'NIE'

Test #12:

score: 0
Accepted
time: 62ms
memory: 24112kb

input:

199999 199998
27735 110383
157138 117109
21107 95911
27141 58936
1514 195135
106403 63473
66162 42639
21681 114598
53954 191710
110249 143780
40636 40124
11560 51678
2778 182082
60435 105451
198676 123935
67639 115704
176195 189982
52257 8366
99743 141742
147381 28925
190341 131308
159677 5040
6138 ...

output:

NIE

result:

ok single line: 'NIE'

Test #13:

score: 0
Accepted
time: 2ms
memory: 11376kb

input:

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

output:

NIE

result:

ok single line: 'NIE'

Test #14:

score: 0
Accepted
time: 8ms
memory: 14272kb

input:

40030 40029
27049 14668
38975 18442
35811 5302
17535 12299
15998 29692
2477 9551
30589 13238
21558 20519
14120 37711
3010 28910
20472 29630
20470 30673
20684 12059
34197 17012
11419 29902
27976 6142
17829 29836
17033 1563
28681 11276
15975 4662
35715 1653
4390 29700
20484 19601
35245 22179
35694 105...

output:

7876944195050

result:

ok single line: '7876944195050'

Test #15:

score: 0
Accepted
time: 63ms
memory: 24100kb

input:

200000 199999
194326 144191
182448 172442
33303 58743
195157 142391
124650 181319
48631 75861
194887 75085
871 75209
128403 22324
1911 96598
172868 55033
158652 188139
96224 69860
69359 69490
184520 11792
191959 42157
131482 19144
107935 150093
67117 41377
9963 116441
65600 112397
64802 13426
37419 ...

output:

23606567643085

result:

ok single line: '23606567643085'

Test #16:

score: 0
Accepted
time: 60ms
memory: 24044kb

input:

200000 199999
52436 11641
79984 114804
111668 33543
137247 48090
9645 65795
184747 39611
11610 159313
22638 145697
63222 136367
32014 151563
93890 110893
116729 104704
156341 117458
98118 56463
18222 199014
16706 14372
187937 105132
117178 156199
38056 104887
72658 192287
171805 72070
114790 84610
1...

output:

23902024445030

result:

ok single line: '23902024445030'

Test #17:

score: 0
Accepted
time: 2ms
memory: 8788kb

input:

199000 199000
56063 29441
95944 92411
160503 142093
170757 96332
25224 46198
58983 137544
22176 91206
112508 87842
147759 138236
64654 75242
89467 126313
169923 41227
76585 85194
105242 18476
155335 62578
90527 108821
4035 170280
185455 189112
132037 25888
54529 101925
157500 26166
108961 86259
9757...

output:

NIE

result:

ok single line: 'NIE'

Test #18:

score: 0
Accepted
time: 0ms
memory: 10168kb

input:

1 0

output:

0

result:

ok single line: '0'

Test #19:

score: 0
Accepted
time: 2ms
memory: 12460kb

input:

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

output:

10737418236

result:

ok single line: '10737418236'

Test #20:

score: 0
Accepted
time: 8ms
memory: 13940kb

input:

40031 40030
26578 5228
15299 28135
6016 20513
9336 32838
7661 35534
1535 15919
6750 24484
12971 28515
35233 3039
19322 9954
12834 31329
37396 28591
35252 16624
31292 11428
26214 31352
34810 2666
16739 33210
16918 11923
40008 18925
4887 17921
13040 22276
17563 13112
11518 18366
14528 4093
24225 19386...

output:

14145979718895

result:

ok single line: '14145979718895'

Test #21:

score: 0
Accepted
time: 0ms
memory: 9212kb

input:

1000 199999
604 484
954 820
91 541
904 310
668 766
595 5
51 946
216 943
896 447
732 702
416 367
409 634
301 847
981 844
730 350
964 313
296 117
941 104
274 497
670 597
324 805
265 248
71 747
681 795
458 762
241 703
543 158
270 706
192 677
212 10
121 263
603 858
455 610
18 104
806 366
846 914
334 408...

output:

NIE

result:

ok single line: 'NIE'

Test #22:

score: 0
Accepted
time: 56ms
memory: 24164kb

input:

200000 199999
168916 189843
109020 119772
81186 19849
7072 27937
174905 77802
164987 111000
198561 161204
62743 121413
149808 156301
75104 165109
112830 151209
72295 77101
76375 19204
136608 198378
76406 199590
57764 154129
48910 116785
111401 109977
87838 139157
77747 194517
112299 158877
185275 96...

output:

35299787196240

result:

ok single line: '35299787196240'

Test #23:

score: 0
Accepted
time: 54ms
memory: 24100kb

input:

200000 199999
144147 72071
114561 93962
18776 127417
130404 34047
106654 44269
877 20752
140480 199128
141143 78428
160246 101224
95841 5378
90561 149381
46943 61769
80221 35510
167564 130060
182389 63999
133132 155106
43012 117979
130191 22893
25824 68379
182453 163277
116025 191932
141767 110874
2...

output:

13471994708663

result:

ok single line: '13471994708663'

Test #24:

score: 0
Accepted
time: 62ms
memory: 24044kb

input:

199022 199021
136856 142915
168114 180648
114369 95091
125209 96808
93791 137894
89954 65498
26012 135123
122911 34709
176448 184389
128555 111094
191371 72347
80760 145410
51727 84726
103043 193579
141324 157740
171547 192675
187925 59783
25672 137859
18921 39802
116494 99049
160099 107838
174119 1...

output:

NIE

result:

ok single line: 'NIE'

Test #25:

score: 0
Accepted
time: 39ms
memory: 21904kb

input:

135166 135165
45419 54604
81453 105593
26402 28999
28608 89965
120776 48533
76603 106963
113574 58088
23777 56709
101693 65039
109717 38482
122783 96461
45844 84577
3082 128381
115407 39083
95790 43653
67587 105709
113512 39408
126194 36234
105195 76163
109746 69388
24031 57058
128212 37827
34749 40...

output:

58091192996351

result:

ok single line: '58091192996351'

Test #26:

score: 0
Accepted
time: 47ms
memory: 24048kb

input:

200000 199999
150717 119718
32056 73883
126212 34545
182533 28010
141402 149238
51959 139591
36371 50670
194752 107965
185788 1409
121675 108149
94700 143764
73222 150872
162334 198172
16821 83405
83067 4652
197790 133843
83898 98608
32319 22267
143182 134079
175348 199905
131416 48285
9468 106710
3...

output:

NIE

result:

ok single line: 'NIE'

Test #27:

score: 0
Accepted
time: 10ms
memory: 15076kb

input:

40032 40031
34094 27327
12483 36998
9590 15140
6825 17291
21512 14523
15997 35435
12683 11420
7412 34363
31608 21178
10745 31983
15950 34840
27919 37670
32231 11949
3665 23642
11903 28209
18678 39455
26052 11954
17609 17649
31093 29946
23007 18707
31229 280
20426 31569
13200 5992
16326 17750
25769 3...

output:

27538832545051

result:

ok single line: '27538832545051'

Test #28:

score: 0
Accepted
time: 61ms
memory: 24100kb

input:

200000 199999
125946 186376
46135 158303
30293 185162
33144 166227
108294 45473
11191 184006
153910 101067
159317 162799
57288 177375
2252 138193
132712 99328
149544 97675
170281 96724
75508 185069
28849 20704
123673 111393
22771 70952
55087 133008
187298 62738
16599 96660
154698 45861
166006 79880
...

output:

NIE

result:

ok single line: 'NIE'

Test #29:

score: -100
Wrong Answer
time: 42ms
memory: 24244kb

input:

200000 199999
41295 166839
172502 151742
26771 101088
93341 20156
142549 198534
199851 45677
30164 126117
166839 101899
166839 96955
25771 196347
188077 166839
101750 59424
166839 147664
117410 129918
159681 166839
113507 131406
70324 151745
113689 166839
119444 118485
132056 166839
35514 159529
141...

output:

65

result:

wrong answer 1st lines differ - expected: 'NIE', found: '65'