QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#514517#4686. ToursPetroTarnavskyiWA 1ms3628kbC++231.1kb2024-08-11 02:37:112024-08-11 02:37:11

Judging History

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

  • [2024-08-11 02:37:11]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3628kb
  • [2024-08-11 02:37:11]
  • 提交

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;


int ans = 0;

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

void dfs(int v)
{
	used[v] = 1;
	for(int to : g[v])
	{
		if(used[to] == 0)
		{
			d[to] = d[v] + 1;
			dfs(to);
			continue;
		}
		if(used[to] == 1)
			ans = gcd(ans, d[v] - d[to] + 1);
	}
	used[v] = 2;
}



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(i, 0, n)
	{
		fill(d, d + n, 0);
		fill(used, used + n, 0);
		dfs(i);
	}
	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: 1ms
memory: 3496kb

input:

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

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3628kb

input:

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

output:

1

result:

wrong answer Answer contains longer sequence [length = 2], but output contains 1 elements