QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#666850#4686. ToursArgharizaWA 2ms10636kbC++171.4kb2024-10-22 20:11:472024-10-22 20:11:55

Judging History

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

  • [2024-10-22 20:11:55]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:10636kb
  • [2024-10-22 20:11:47]
  • 提交

answer

// Problem: P6914 [ICPC2015 WF] Tours
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P6914
// Memory Limit: 500 MB
// Time Limit: 1880 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define R(i, x, y) for (int i = (x); i >= (y); i--)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
bool Mbe;

const int N = 2e5 + 5;

int n, m, k;
int vs[N], c[N], d[N];

vector<int> G[N];

void dfs(int u, int f) {
	vs[u] = 1;
	for (int v : G[u]) {
		if (vs[v]) {
			if (v != f) {
				k = __gcd(k, max(d[u], d[v]) - min(d[u], d[v]) + 1);
			}
			continue;
		}
		d[v] = d[u] + 1;
		dfs(v, u);
	}
}

void solve() {
	cin >> n >> m;
	F (i, 1, m) {
		int u, v;
		cin >> u >> v;
		G[u].eb(v), G[v].eb(u);
	}
	F (i, 1, n) {
		if (!vs[i]) {
			dfs(i, 0);
		}
	}
	F (i, 1, n) {
		if (k % i == 0) {
			cout << i << ' ';
		}
	}
}

bool Med;
int main() {
	// FIO("");
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cerr << (&Mbe - &Med) / 1048576.0 << " MB\n";
	int T = 1;
	// cin >> T;
	while (T--) solve();
	cerr << (int)(1e3 * clock() / CLOCKS_PER_SEC) << " ms\n";
	return 0;
}

详细

Test #1:

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

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: 2ms
memory: 9676kb

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: 2ms
memory: 10636kb

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: 2ms
memory: 9040kb

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: -100
Wrong Answer
time: 1ms
memory: 8608kb

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 4 

result:

wrong answer Output contains longer sequence [length = 3], but answer contains 2 elements