QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#514531 | #4686. Tours | PetroTarnavskyi | WA | 1ms | 3908kb | C++23 | 1.8kb | 2024-08-11 02:45:53 | 2024-08-11 02:45:55 |
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;
const int N = 1 << 17;
VI g[N];
int d[N];
int used[N];
vector<VI> cycle;
VI st;
void dfs(int v)
{
st.PB(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)
{
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);
}
dfs(0);
int ans = 0;
shuffle(ALL(cycle), rng);
FOR(i, 0, SZ(cycle))
{
sort(ALL(cycle[i]));
ans = gcd(ans, SZ(cycle[i]));
}
FOR(i, 0, SZ(cycle))
{
FOR(j, 0, i)
{
int Pi = 0, Pj = 0, cnt = 0;
while(Pi < SZ(cycle[i]) && Pj < SZ(cycle[j]))
{
if(cycle[i][Pi] == cycle[j][Pj])
{
Pi++;
Pj++;
cnt++;
continue;
}
if(cycle[i][Pi] < cycle[j][Pj])
Pi++;
else
Pj++;
}
if(cnt != 0)
ans = gcd(ans, 2 * (cnt - 1));
}
if(1.0 * clock() / CLOCKS_PER_SEC > 2.5)
break;
}
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: 3680kb
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: 3908kb
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