QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#502859#6666. Grafwsyear0 293ms54576kbC++172.9kb2024-08-03 15:18:532024-08-03 15:18:54

Judging History

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

  • [2024-08-03 15:18:54]
  • 评测
  • 测评结果:0
  • 用时:293ms
  • 内存:54576kb
  • [2024-08-03 15:18:53]
  • 提交

answer

// Author: Klay Thompson
// Problem: P10829 [COTS/CETS 2023] 三元图 Graf
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P10829
// Memory Limit: 512 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#ifdef dbg
#define D(...) fprintf(stderr, __VA_ARGS__)
#define DD(...) D("[Debug] "#__VA_ARGS__ " = "), \
              debug_helper::debug(__VA_ARGS__), D("\n")
#include "C:\Users\wsyear\Desktop\OI\templates\debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

template<class T> void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T> void chkmx(T &x, T y) { if (y > x) x = y; }

using namespace std;

const int maxn = 500010;

int n, m, dfn[maxn], low[maxn], stk[maxn], sz[maxn], mxsz[maxn], vis[maxn], asz, rt, timer, top, tot;
vector<int> e[maxn], g[maxn];

void tarjan(int u) {
  dfn[u] = low[u] = ++timer, stk[++top] = u;
  for (int v : e[u]) {
    if (!dfn[v]) {
      tarjan(v), chkmn(low[u], low[v]);
      if (low[v] >= dfn[u]) {
        tot++;
        g[u].emplace_back(tot);
        g[tot].emplace_back(u);
        while (stk[top] != v) {
          g[stk[top]].emplace_back(tot);
          g[tot].emplace_back(stk[top]);
          top--;
        }
        g[v].emplace_back(tot);
        g[tot].emplace_back(v);
        top--;
      }
    } else {
      chkmn(low[u], dfn[v]);
    }
  }
}

void findrt(int u, int fa) {
  sz[u] = (u <= n), mxsz[u] = 0;
  for (int v : g[u]) {
    if (vis[v] || v == fa) continue;
    findrt(v, u), sz[u] += sz[v];
    chkmx(mxsz[u], sz[v]);
  }
  chkmx(mxsz[u], asz - sz[u]);
  if (mxsz[u] <= asz / 2) rt = u;
}

void dfs(int u, int fa) {
  sz[u] = (u <= n);
  for (int v : g[u]) {
    if (vis[v] || v == fa) continue;
    findrt(v, u), sz[u] += sz[v];
  }
}

void solve(int u, int bsz) {
  if (bsz == 1) return;
  if (bsz % 3 != 0) cout << "ne\n", exit(0);
  vis[u] = 1;
  vector<int> son;
  for (int v : g[u]) {
    if (vis[v]) continue;
    dfs(v, u), son.emplace_back(sz[v]);
  }
  if (SZ(son) != 3 || *max_element(ALL(son)) != bsz / 3) cout << "ne\n", exit(0);
  for (int v : g[u]) {
    if (vis[v]) continue;
    asz = bsz / 3, rt = 0, findrt(v, u), solve(rt, bsz / 3);
  }
}

int main() {
  cin.tie(nullptr) -> ios::sync_with_stdio(false);
  cin >> n >> m;
  rep (i, 1, m) {
    int u, v;
    cin >> u >> v;
    e[u].emplace_back(v);
    e[v].emplace_back(u);
  }
  tot = n, tarjan(1);
  rep (i, 1, n) if (!dfn[i]) cout << "ne\n", exit(0);
  asz = n, rt = 0, findrt(1, 0), solve(rt, n);
  cout << "da\n";
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 15
Accepted
time: 3ms
memory: 37488kb

input:

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

output:

da

result:

ok single line: 'da'

Test #2:

score: 15
Accepted
time: 0ms
memory: 37444kb

input:

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

output:

da

result:

ok single line: 'da'

Test #3:

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

input:

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

output:

da

result:

wrong answer 1st lines differ - expected: 'ne', found: 'da'

Subtask #2:

score: 0
Wrong Answer

Test #35:

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

input:

729 1093
340 310
430 713
576 240
138 297
618 162
328 418
143 713
568 220
252 387
219 400
593 491
330 472
722 643
679 598
356 112
701 213
344 408
500 190
225 72
351 688
283 542
215 449
135 194
306 382
266 83
576 289
563 721
345 656
567 694
580 355
127 487
352 310
687 322
620 520
583 466
678 308
19 10...

output:

da

result:

wrong answer 1st lines differ - expected: 'ne', found: 'da'

Subtask #3:

score: 0
Wrong Answer

Test #69:

score: 15
Accepted
time: 129ms
memory: 53840kb

input:

177147 265719
79646 110581
42107 166686
174516 92541
11418 84874
89568 79680
101533 167489
143016 26545
83401 102450
122789 91031
140172 64836
143906 82843
45757 98991
164963 130550
33432 152305
80043 16055
49162 39443
59476 89357
146429 111186
99327 115855
166381 89990
91164 139281
121510 124610
16...

output:

ne

result:

ok single line: 'ne'

Test #70:

score: 15
Accepted
time: 132ms
memory: 54452kb

input:

177147 265719
38681 77992
106972 53905
88649 110477
113934 98724
78662 109263
134699 83502
31991 92472
126170 144
119650 132169
84458 92531
24682 66176
131541 177081
97342 131339
103685 102763
130223 36375
142925 66285
105340 117815
111137 162166
43022 15242
120307 54486
78258 164394
52991 104308
65...

output:

ne

result:

ok single line: 'ne'

Test #71:

score: 15
Accepted
time: 215ms
memory: 52396kb

input:

177147 265719
80151 35717
121902 3023
160759 169382
24887 142159
40782 159514
23600 98839
121180 62418
122763 152478
148678 114794
11943 72581
173127 2884
97280 4969
155030 45742
120300 148466
134742 140635
79483 24583
71636 91841
140421 126108
44434 53426
133218 79051
161302 161964
59589 111719
961...

output:

ne

result:

ok single line: 'ne'

Test #72:

score: 15
Accepted
time: 132ms
memory: 52028kb

input:

177147 265719
23535 148931
151961 42693
126734 69633
41675 97286
148290 110970
18165 83792
5192 133074
101128 76523
76671 146056
37165 145496
108304 76746
47477 140906
73419 48220
39470 54859
81251 91381
88943 87801
102113 126514
153800 35348
116125 49494
114248 11690
150336 26095
40669 90388
3210 9...

output:

ne

result:

ok single line: 'ne'

Test #73:

score: 0
Wrong Answer
time: 206ms
memory: 52792kb

input:

177147 265720
170712 62225
99915 128584
115624 72186
110450 90393
65021 158547
110390 161798
28967 132365
78897 47218
68752 69351
40606 17503
79654 32708
98155 146206
156781 52063
126696 159590
11625 167534
29472 10242
143508 43084
154423 175381
150212 141153
5882 3903
142063 39110
158366 31577
2263...

output:

da

result:

wrong answer 1st lines differ - expected: 'ne', found: 'da'

Subtask #4:

score: 0
Wrong Answer

Test #103:

score: 50
Accepted
time: 92ms
memory: 53684kb

input:

177147 265719
132920 57252
64370 50983
162323 103641
126430 64347
64421 107962
35533 30427
171597 160614
120187 121996
103235 117200
122594 156637
121481 108177
115386 6337
28269 153079
43775 171594
164425 165290
59340 170257
20858 74213
162837 103195
171976 121082
68853 33317
152714 8959
47095 9036...

output:

ne

result:

ok single line: 'ne'

Test #104:

score: 50
Accepted
time: 181ms
memory: 51460kb

input:

177147 265720
98251 19107
36929 5082
59297 17482
166275 130189
125119 161493
151977 35937
4540 92380
52037 36475
105282 76892
8397 7997
162679 100647
12685 34568
53625 30405
136245 147693
95596 151955
66119 156086
92822 98840
66600 97472
42324 130091
34459 150929
81661 38148
1174 30859
113776 90353
...

output:

ne

result:

ok single line: 'ne'

Test #105:

score: 50
Accepted
time: 31ms
memory: 40620kb

input:

59049 88572
14041 31673
1168 11350
38714 28802
37877 22048
49987 22707
26786 49980
2818 13974
10003 17358
51907 30794
16816 20935
8685 53622
49148 54509
3371 26238
50806 4657
57731 38759
38131 9810
28974 19191
5485 27763
9140 36793
45914 17712
23433 31979
29334 8721
7313 42734
12130 24011
36906 5164...

output:

ne

result:

ok single line: 'ne'

Test #106:

score: 50
Accepted
time: 116ms
memory: 53748kb

input:

177147 265719
119867 167070
130132 12752
120764 56321
15572 66501
139543 82691
70068 42197
61383 135281
122332 161897
68678 68884
51691 172281
33415 150511
101102 101300
108117 151586
39194 21123
173495 82522
134499 170131
15461 53912
114257 106087
137475 32697
31578 172314
139488 145536
118015 1288...

output:

ne

result:

ok single line: 'ne'

Test #107:

score: 50
Accepted
time: 145ms
memory: 54464kb

input:

177147 265719
32229 30186
75313 76163
111944 168135
43914 37095
22266 44860
166052 93754
169557 55704
108797 163872
45432 112994
80343 100383
110188 66178
135008 105902
155873 72661
44225 151314
2720 88316
66950 133820
20039 85930
91897 17236
40370 91049
112750 27809
48067 13266
126431 53691
127666 ...

output:

ne

result:

ok single line: 'ne'

Test #108:

score: 50
Accepted
time: 43ms
memory: 41960kb

input:

59049 88572
26511 33490
28852 45905
27461 12238
3574 21240
10401 47111
25108 30094
41731 23065
34029 50912
24637 3051
39816 52369
17677 44545
29603 11717
24661 41876
6322 19702
11178 38322
12480 26080
47105 3194
12178 36578
32634 16221
25540 24583
42234 24601
15926 7470
5428 20505
18895 24343
6641 2...

output:

ne

result:

ok single line: 'ne'

Test #109:

score: 50
Accepted
time: 220ms
memory: 51760kb

input:

177147 265719
109974 161035
10257 149062
121470 37587
101821 92037
121099 27132
31616 170660
46299 85346
105465 61610
133310 53913
20419 23471
11021 49161
161237 108062
27418 106411
42549 75808
90998 78111
32550 19003
10562 170797
77403 67800
34756 24189
88268 56154
14749 154026
5889 159314
104655 1...

output:

ne

result:

ok single line: 'ne'

Test #110:

score: 50
Accepted
time: 216ms
memory: 51576kb

input:

177147 265719
108664 58201
64269 6343
120585 157969
151929 136534
168726 15269
25610 60139
11181 158806
139226 97957
107369 141067
135947 160932
162045 50711
105512 5940
172321 5888
7221 99888
120318 20857
24810 151590
135587 8881
143228 24034
6096 39018
73071 58377
173193 124153
97410 69946
74197 7...

output:

ne

result:

ok single line: 'ne'

Test #111:

score: 50
Accepted
time: 138ms
memory: 54576kb

input:

177147 265719
32981 44699
147062 61378
88263 172913
58385 30028
98963 22183
21517 65343
40334 104039
63687 1318
136538 117786
2824 90817
170979 107527
93628 112008
35891 28456
164720 154877
2494 115639
119501 113995
31926 105269
92857 99010
174834 17842
11538 142621
125432 105466
135353 157000
68024...

output:

ne

result:

ok single line: 'ne'

Test #112:

score: 50
Accepted
time: 142ms
memory: 53488kb

input:

177147 265719
167966 17672
92091 174891
69156 176406
144245 124379
124290 42270
59738 92303
86870 83034
79441 52547
15702 45945
164475 43564
132133 61402
27448 122029
45378 131195
35639 152970
550 29347
134069 145338
111946 144913
58629 120345
90261 66787
8482 156139
106048 76828
151397 165340
22520...

output:

ne

result:

ok single line: 'ne'

Test #113:

score: 50
Accepted
time: 293ms
memory: 51824kb

input:

177147 265720
84549 59066
8533 97512
95654 45173
28525 150968
86580 149227
57726 67651
52781 160528
97950 141266
100850 14838
166553 138190
61634 14254
57547 24000
168524 11255
116362 130964
170815 172567
120074 7542
128396 3289
29898 125597
163966 69876
50139 142020
84785 71240
22378 26807
135344 1...

output:

ne

result:

ok single line: 'ne'

Test #114:

score: 50
Accepted
time: 204ms
memory: 51576kb

input:

177147 265719
68898 132920
29665 73506
20531 169214
103475 58989
61733 32239
151574 63398
119411 169525
24793 25207
41292 44383
133706 111802
174419 1600
74876 147063
161499 174674
10278 7799
123599 8481
146302 166032
1313 90856
60646 95512
106779 134984
41603 43637
15001 37449
153582 123699
108004 ...

output:

ne

result:

ok single line: 'ne'

Test #115:

score: 0
Wrong Answer
time: 61ms
memory: 41820kb

input:

59049 88573
48002 20129
7630 33065
13470 58907
56979 49428
24783 51171
35198 55138
26000 13842
56782 34295
54165 5732
52635 46706
40182 1575
48144 56529
25104 1814
30791 45557
24736 48013
51257 51882
26582 54128
26950 47776
18073 51674
24939 54097
24871 44506
23664 28536
3218 34786
44770 14839
46589...

output:

da

result:

wrong answer 1st lines differ - expected: 'ne', found: 'da'