QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#514517 | #4686. Tours | PetroTarnavskyi | WA | 1ms | 3628kb | C++23 | 1.1kb | 2024-08-11 02:37:11 | 2024-08-11 02:37:11 |
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;
}
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;
}
Details
Tip: Click on the bar to expand more detailed information
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