QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#514519 | #4686. Tours | PetroTarnavskyi | WA | 1ms | 3880kb | C++23 | 1.2kb | 2024-08-11 02:38:05 | 2024-08-11 02:38:06 |
Judging History
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;
}
mt19937 rng(47);
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)
{
shuffle(ALL(g[i]), rng);
}
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: 3820kb
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: 3880kb
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