QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#514533 | #4686. Tours | PetroTarnavskyi | WA | 1ms | 3912kb | C++23 | 1.8kb | 2024-08-11 02:47:05 | 2024-08-11 02:47: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;
const int N = 1 << 17;
VI g[N];
int d[N];
int used[N];
vector<VI> cycle;
VI st;
void dfs(int v, int p)
{
st.PB(v);
used[v] = 1;
for(int to : g[v])
{
if(used[to] == 0)
{
d[to] = d[v] + 1;
dfs(to, v);
continue;
}
if(used[to] == 1 && to != p)
{
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, -1);
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++;
}
//cerr << cnt << "\n";
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: 3560kb
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: 1ms
memory: 3700kb
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: 1ms
memory: 3688kb
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: 0ms
memory: 3676kb
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: 3912kb
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