QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#392263 | #4686. Tours | oscaryang | WA | 0ms | 4068kb | C++17 | 1.4kb | 2024-04-17 13:24:56 | 2024-04-17 13:24:56 |
Judging History
answer
#include<bits/stdc++.h>
#define ull unsigned long long
#define vc vector
#define pb emplace_back
#define pii pair<int, int>
#define mkp make_pair
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define lep(i, a, b) for(int i = (a); i >= (b); --i)
using namespace std;
bool st;
mt19937_64 gen(time(0));
inline int read() {
int x = 0, w = 0; char ch = getchar(); while(!isdigit(ch)) w |= (ch == '-'), ch = getchar();
while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return w ? -x : x;
}
const int N = 2005;
int n, m, dep[N];
ull val[N];
vc <int> G[N];
map <ull, int> Map;
inline void dfs (int x, int fa = 0) {
for (auto y : G[x]) if (y != fa) {
if (!dep[y]) dep[y] = dep[x] + 1, dfs (y, x), val[x] ^= val[y];
else if (dep[y] < dep[x]) {
ull v = gen ();
val[x] ^= v; val[y] ^= v;
}
}
if (fa && val[x]) ++ Map[val[x]];
}
bool ed;
signed main() {
// freopen ("a.in", "r", stdin);
cerr << (&ed - &st) / 1024 / 1024 << "MB ---------------------------" << endl;
n = read (); m = read ();
for (int i = 1, u, v; i <= m; i++)
u = read (), v = read (), G[u].pb (v), G[v].pb (u);
rep (i, 1, n) if (!dep[i]) dep[i] = 1, dfs (i);
int ans = 0;
if (!Map.size ()) ans = n;
else {
for (auto [u, v] : Map) ans = ans ? __gcd (ans, v + 1) : v + 1;
}
rep (i, 1, n) if (ans % i == 0) printf ("%d ", i);
putchar (10);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 4068kb
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: 0ms
memory: 3936kb
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: 0ms
memory: 4008kb
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: 3928kb
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: 0ms
memory: 3876kb
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
result:
wrong answer Answer contains longer sequence [length = 2], but output contains 1 elements