QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#514549#4686. ToursPetroTarnavskyiRE 411ms20320kbC++231.7kb2024-08-11 03:03:472024-08-11 03:03:48

Judging History

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

  • [2024-08-11 03:03:48]
  • 评测
  • 测评结果:RE
  • 用时:411ms
  • 内存:20320kb
  • [2024-08-11 03:03:47]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef long double db;


const int N = 1 << 11;
VI g[N];
int used[N];


vector<VI> cycle;
VI st;
void dfs(int v, int p)
{
	st.PB(v);
	used[v] = 1;
	for(int to : g[v])
	{
		if(used[to] == 0)
		{
			dfs(to, v);
			continue;
		}
		if(used[to] == 1 && to != p && st[0] == to)
		{
			VI cyc;
			RFOR(j, SZ(st), 0)
			{
				cyc.PB(st[j]);
				if(st[j] == to)
					break;
			}
			cycle.PB(cyc);
		}
	}
	st.pop_back();
	used[v] = 2;
}

mt19937 rng;

int main()
{
	ios::sync_with_stdio(0); 
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	
	FOR(i, 0, m)
	{
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].PB(b);
		g[b].PB(a);
	}
	FOR(v, 0, n)
	{
		fill(used, used + n, 0);
		dfs(v, -1);
	}

	int ans = 0;
	map<PII, bitset<N>> inCyc;
	FOR(i, 0, SZ(cycle))
	{
		FOR(j, 0, SZ(cycle[i]))
		{
			int v = cycle[i][j];
			int to = cycle[i][(j + 1) % SZ(cycle[i])];
			
			if(v > to)
				swap(v, to);
			inCyc[MP(v, to)][i] = 1;
		}
	}
	map<VI, int> cnt;
	for(auto [_, inCycV] : inCyc)
	{
		VI cur(N);
		FOR(j, 0, N)
			cur[j] = inCycV[j];
		cnt[cur]++;
	}
	for(auto [_, c] : cnt)
		ans = gcd(ans, c);
	


	VI res;
	FOR(x, 1, n + 1)
		if(ans % x == 0)
			res.PB(x);
	FOR(i, 0, SZ(res))
	{
		if(i)
			cout << " ";
		cout << res[i];
	}
	cout << "\n";
	
	
	return 0;
}

详细

Test #1:

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

input:

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

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

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

output:

1 3

result:

ok 2 number(s): "1 3"

Test #3:

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

input:

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

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

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

output:

1 3

result:

ok 2 number(s): "1 3"

Test #5:

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

input:

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

output:

1 2

result:

ok 2 number(s): "1 2"

Test #6:

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

input:

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

output:

1

result:

ok 1 number(s): "1"

Test #7:

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

input:

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

output:

1 3

result:

ok 2 number(s): "1 3"

Test #8:

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

input:

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

output:

1

result:

ok 1 number(s): "1"

Test #9:

score: 0
Accepted
time: 411ms
memory: 20320kb

input:

2000 2000
1036 1254
1453 1496
342 1815
186 346
840 1555
138 1503
416 1376
660 1253
1279 1799
209 1554
624 1278
792 884
333 1703
393 894
551 1192
1705 1805
302 930
115 1384
151 1156
71 209
82 1637
858 1854
19 1798
348 703
1692 1744
261 1029
143 1631
336 1227
1493 1564
493 1966
553 1587
953 1128
214 1...

output:

1 2 4 5 8 10 16 20 25 40 50 80 100 125 200 250 400 500 1000 2000

result:

ok 20 numbers

Test #10:

score: 0
Accepted
time: 89ms
memory: 6784kb

input:

1820 1872
677 1254
114 163
1751 1815
532 1640
290 380
253 1429
174 1163
1005 1431
521 1324
37 1553
369 1764
658 1170
1456 1574
224 663
752 1460
128 441
831 1013
730 1583
500 983
374 1274
1394 1478
422 1223
1310 1632
1133 1508
914 1258
151 907
221 233
549 1374
342 895
1591 1699
1041 1273
231 747
1419...

output:

1 2 3 6 9 18

result:

ok 6 numbers

Test #11:

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

input:

1521 1584
1138 1283
95 542
137 1042
1043 1390
147 1396
382 709
651 828
909 1124
286 1485
31 171
925 1254
360 501
900 1229
69 1358
166 199
633 1178
310 1390
679 1482
844 1333
761 1208
38 1512
449 875
13 1467
77 217
622 736
45 1163
365 1346
106 1084
494 832
465 930
283 771
704 1468
375 870
82 1336
113...

output:

1 2 3 4 6 12

result:

ok 6 numbers

Test #12:

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

input:

1433 1467
43 1268
90 1143
237 271
444 1375
232 1407
1026 1139
861 943
981 1003
77 1229
416 966
606 1370
351 438
687 1379
1030 1186
1373 1428
715 762
553 1426
238 1012
120 618
345 857
827 1118
548 1085
245 333
82 910
202 570
80 781
666 797
122 1022
75 989
674 881
298 1139
160 584
801 1085
607 715
751...

output:

1 3 9

result:

ok 3 number(s): "1 3 9"

Test #13:

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

input:

1569 1625
1043 1553
57 369
481 1231
99 227
113 262
239 354
175 887
819 1230
27 115
76 820
1086 1498
482 1193
1299 1447
570 604
121 508
100 208
77 572
52 1296
198 639
103 945
256 381
745 1173
1033 1350
13 1414
233 1399
402 1417
1394 1441
206 623
264 482
1155 1336
1176 1433
50 1066
542 850
666 1508
80...

output:

1 5

result:

ok 2 number(s): "1 5"

Test #14:

score: 0
Accepted
time: 27ms
memory: 4948kb

input:

1035 1072
448 654
201 211
139 650
224 255
430 883
494 517
199 999
717 763
661 813
145 574
68 908
626 990
7 805
54 875
600 968
279 462
335 543
266 665
598 676
177 447
790 1034
273 909
475 814
464 973
210 560
290 905
650 708
288 994
10 183
261 564
492 967
273 300
481 735
184 1013
123 911
536 550
460 5...

output:

1 2 4 8

result:

ok 4 number(s): "1 2 4 8"

Test #15:

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

input:

162 198
41 83
15 121
29 76
62 75
78 114
58 80
5 75
85 119
45 137
3 56
149 156
46 63
79 107
125 150
33 78
43 149
27 87
20 33
13 136
60 90
60 110
30 97
102 152
25 31
6 79
24 67
16 78
68 115
77 78
103 124
117 161
117 139
55 67
19 146
45 112
26 104
45 49
108 144
145 154
130 134
13 111
57 78
35 159
4 65
...

output:

1 3

result:

ok 2 number(s): "1 3"

Test #16:

score: 0
Accepted
time: 105ms
memory: 6328kb

input:

1894 1932
384 1664
1204 1508
733 1583
818 1515
879 1799
197 1165
657 919
559 1893
241 1104
347 1283
516 916
179 1041
305 477
1116 1135
1254 1561
280 742
269 975
34 862
1033 1659
74 382
307 1600
99 1553
1298 1565
955 1579
308 478
947 1595
1686 1793
190 1836
878 1260
732 1498
889 1570
436 1723
393 100...

output:

1 7

result:

ok 2 number(s): "1 7"

Test #17:

score: -100
Runtime Error

input:

63 1953
24 25
30 53
16 28
20 36
34 51
33 52
3 11
9 35
28 52
52 54
22 51
33 46
2 45
35 43
4 48
4 35
2 7
26 59
21 35
21 43
9 58
37 63
7 26
17 32
7 11
34 56
6 54
18 62
33 44
15 52
50 53
17 46
12 42
9 31
9 11
35 47
1 13
21 42
26 43
2 24
27 35
5 39
6 9
1 51
16 46
6 62
18 34
59 63
22 62
22 53
14 39
49 55
...

output:


result: