QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#392269 | #4686. Tours | oscaryang | WA | 0ms | 4036kb | C++17 | 1.4kb | 2024-04-17 13:45:25 | 2024-04-17 13:45:25 |
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) {
int ad = 1;
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 (); ad = 2;
val[x] ^= v; val[y] ^= v;
}
}
if (fa && val[x]) Map[val[x]] += ad;
}
bool ed;
signed main() {
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) : v;
}
rep (i, 1, n) if (ans % i == 0) printf ("%d ", i);
putchar (10);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4032kb
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: 4036kb
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: 3968kb
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: 4032kb
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: 0
Accepted
time: 0ms
memory: 3992kb
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
result:
ok 2 number(s): "1 2"
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3992kb
input:
6 7 1 2 2 3 3 4 4 5 5 6 1 6 3 6
output:
1 2
result:
wrong answer Output contains longer sequence [length = 2], but answer contains 1 elements