QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#191768#6123. JAG Graph Isomorphismucup-team1209#WA 97ms35160kbC++202.2kb2023-09-30 11:00:402023-09-30 11:00:41

Judging History

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

  • [2023-09-30 11:00:41]
  • 评测
  • 测评结果:WA
  • 用时:97ms
  • 内存:35160kb
  • [2023-09-30 11:00:40]
  • 提交

answer

#include<bits/stdc++.h>
using std::cin;
using std::cout;
const int N = 300005;
using ll = long long;
using u64 = unsigned long long;
using pr = std::pair<int, int>;
const ll inf = 1e18;

std::map<std::vector<int>, int> map;
int cnt;

int get(std::vector<int> v) {
	if(map.count(v)) return map[v];
	return map[v] = ++cnt;
}

int n;

const int mod = 920028467;
const int base = 124124;

struct graph {
	std::vector<int> go[N];
	std::vector<int> st, cyc;
	int vis[N];
	void dfs0(int x, int fa = 0) {
		vis[x] = 1;
		st.push_back(x);
		for(int v : go[x]) if(v != fa) {
			if(!vis[v]) {
				dfs0(v, x);
			} else {
				if(!cyc.size()) cyc = std::vector<int>(find(st.begin(), st.end(), v), st.end());
			}
		}
		st.pop_back();
	}
	int h[N];
	void dfs1(int x, int fa = 0) {
		vis[x] = 1;
		std::vector<int> son;
		for(int v : go[x]) if(!vis[v]) {
			dfs1(v);
			son.push_back(h[v]);
		}
		sort(son.begin(), son.end());
		h[x] = ::get(son);
	}
	int w[N * 2];
	std::vector<int> get() {
		for(int i = 1, u, v;i <= n;++i) {
			cin >> u >> v;
			go[u].push_back(v);
			go[v].push_back(u);
		}
		dfs0(1);
		memset(vis, 0, sizeof(vis));
		for(int x : cyc) {
			vis[x] = 1;
		}
		std::vector<int> hs;
		for(int x : cyc) {
			dfs1(x);
			hs.push_back(h[x]);
		}
		return hs;
	}
} g1, g2;
std::vector<int> geths(std::vector<int> hs) {
	std::vector<int> w(hs.size() * 2 + 1);
	int pw = 1;
	for(int i = 0;i < (int) hs.size();++i) pw = (u64) pw * base % mod;
	for(int i = 1;i < (int) hs.size() * 2;++i) {
		w[i] = ((u64) w[i - 1] * base + hs[(i - 1) % hs.size()]) % mod;
	}
	std::vector<int> ans;
	for(int i = hs.size();i < (int) hs.size() * 2;++i) {
		ans.push_back((w[i] + u64(mod - pw) * w[i - hs.size()]) % mod);
	}
	return ans;
}

int chk(std::vector<int> a, std::vector<int> b) {
	if(a.size()!=b.size()) return 0;
	auto it = find(b.begin(),b.end(),a[0]);
	if(it==b.end())return 0;
	rotate(b.begin(),it,b.end());
	return a==b;
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	auto A = g1.get();
	auto B = g2.get();
	auto rB = B;
	reverse(rB.begin(), rB.end());

	if(chk(A,B)||chk(A,rB)) {
		cout << "Yes" << '\n';
	} else {
		cout << "No" << '\n';
	}


}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 24040kb

input:

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

output:

Yes

result:

ok answer is YES

Test #2:

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

input:

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

output:

No

result:

ok answer is NO

Test #3:

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

input:

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

output:

Yes

result:

ok answer is YES

Test #4:

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

input:

903
835 491
695 797
411 56
636 367
122 715
775 564
199 77
31 593
654 460
330 25
555 345
36 527
768 760
378 753
291 51
676 73
227 883
310 389
656 259
603 836
369 901
347 231
543 259
66 772
301 592
711 738
507 499
425 462
27 458
257 328
628 83
184 645
805 495
491 311
635 874
615 259
39 193
715 673
636...

output:

No

result:

ok answer is NO

Test #5:

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

input:

700
520 12
414 245
592 324
396 343
365 93
611 99
163 524
327 310
436 373
646 392
642 15
698 393
599 682
427 341
383 14
218 330
453 441
647 223
14 26
36 118
229 27
56 604
497 177
621 352
178 349
372 257
45 533
44 407
110 343
66 468
564 253
200 27
80 62
50 201
130 5
190 12
140 643
635 130
352 465
223 ...

output:

No

result:

ok answer is NO

Test #6:

score: 0
Accepted
time: 4ms
memory: 22216kb

input:

350
40 299
79 166
204 324
281 292
63 25
326 188
279 70
64 153
145 121
93 188
283 187
339 1
11 10
330 146
124 45
295 65
208 60
131 39
328 21
181 78
276 5
121 62
81 136
248 78
51 115
87 159
346 338
251 133
306 64
298 183
161 42
14 207
5 73
259 89
269 194
334 129
118 82
50 314
246 72
180 68
166 283
249...

output:

Yes

result:

ok answer is YES

Test #7:

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

input:

506
353 288
61 487
475 353
14 427
103 227
280 13
425 238
10 58
173 240
388 498
12 252
260 326
291 385
32 182
429 10
351 88
12 442
449 224
167 14
5 394
133 492
133 447
199 451
220 468
455 10
472 371
128 392
317 240
36 497
144 149
16 224
272 260
260 323
411 297
361 116
494 46
286 116
483 348
96 337
48...

output:

No

result:

ok answer is NO

Test #8:

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

input:

971
648 284
474 937
225 857
112 843
534 919
750 195
81 705
20 524
745 818
410 187
591 423
567 536
945 69
166 165
168 536
348 536
466 914
3 37
23 745
952 662
110 873
153 915
398 539
242 291
548 749
881 836
155 503
599 202
836 186
54 589
361 368
690 387
578 65
153 104
284 456
327 802
706 800
153 950
2...

output:

Yes

result:

ok answer is YES

Test #9:

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

input:

59
17 6
18 55
16 59
35 1
28 2
41 28
58 30
28 29
21 8
20 10
24 27
13 29
58 26
13 22
12 35
8 13
36 15
1 33
5 16
58 11
16 23
52 45
29 57
16 48
31 38
1 27
17 41
14 37
54 50
13 33
59 27
32 13
2 3
13 26
13 34
41 7
54 1
35 43
3 44
31 18
54 51
35 14
39 59
20 29
34 46
59 56
25 32
12 47
25 6
53 26
29 42
32 55...

output:

No

result:

ok answer is NO

Test #10:

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

input:

286
165 14
142 274
11 169
103 182
219 210
61 78
112 273
176 220
29 5
80 254
228 127
223 198
186 74
218 198
272 157
62 251
210 267
142 84
18 276
124 118
126 286
87 53
43 232
60 282
164 274
137 111
198 104
98 211
42 236
94 54
154 168
202 142
124 107
182 165
20 5
239 230
135 171
184 75
212 273
178 41
2...

output:

Yes

result:

ok answer is YES

Test #11:

score: 0
Accepted
time: 4ms
memory: 23836kb

input:

39
16 15
8 4
15 21
36 26
4 6
30 11
3 36
15 31
33 34
5 36
3 19
28 37
27 36
27 25
29 9
11 1
39 18
3 20
2 5
9 21
7 39
32 27
34 21
17 21
3 29
5 15
15 4
36 12
23 27
2 10
6 38
24 36
35 6
14 22
13 14
11 26
5 39
14 11
15 37
1 37
26 5
37 30
13 9
7 14
10 6
11 28
14 33
35 15
8 11
17 27
31 18
30 15
17 13
16 3
1...

output:

No

result:

ok answer is NO

Test #12:

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

input:

650
4 317
341 320
303 241
537 130
365 247
225 255
646 541
499 123
464 144
161 310
139 209
387 151
435 509
294 531
256 461
276 441
181 165
249 305
229 178
90 84
549 5
456 232
587 326
183 407
540 167
207 564
516 465
463 529
149 30
533 497
246 153
9 461
325 301
606 599
274 48
296 389
101 391
394 628
27...

output:

No

result:

ok answer is NO

Test #13:

score: 0
Accepted
time: 3ms
memory: 23612kb

input:

288
91 109
61 38
71 79
114 201
22 133
200 110
88 53
250 42
195 147
239 266
271 116
83 40
178 21
144 254
18 238
204 89
16 88
118 219
219 116
275 34
76 288
234 248
198 49
228 256
29 27
85 132
163 49
190 144
84 255
65 236
185 162
14 70
243 263
220 234
153 205
187 283
96 221
39 166
199 148
7 265
202 229...

output:

No

result:

ok answer is NO

Test #14:

score: -100
Wrong Answer
time: 97ms
memory: 35160kb

input:

116871
39075 32573
116166 73891
46785 26557
109712 67026
96634 74215
20928 27705
74117 37505
41693 113891
93879 112142
29569 17203
22934 79495
70087 92907
28702 82575
21339 116746
66068 100787
91238 12681
48500 112852
80581 76454
92974 88524
24260 112857
36444 115587
93557 74966
48402 38197
21346 74...

output:

No

result:

wrong answer expected YES, found NO