QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#392265 | #4686. Tours | oscaryang | WA | 0ms | 4052kb | C++17 | 1.7kb | 2024-04-17 13:39:47 | 2024-04-17 13:39:47 |
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, le[N], ri[N], DFN, dep[N];
struct edge { int x, y; ull z; } ;
ull val[N];
vc <edge> e;
vc <int> G[N];
map <ull, int> Map;
inline void dfs (int x, int fa = 0) {
le[x] = ++DFN;
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;
e.pb (edge {x, y, v = gen ()});
val[x] ^= v; val[y] ^= v;
}
}
if (fa && val[x]) ++ Map[val[x]];
ri[x] = DFN;
}
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);
for (auto [x, y, z] : e) {
ull val = 0;
for (auto [u, v, w] : e)
if (le[x] <= le[u] && le[x] <= ri[u] && (le[v] <= le[y] || le[v] > ri[y])) val ^= w;
++ Map[val];
}
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: 4044kb
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: 3920kb
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: 3920kb
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: 3936kb
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: 4052kb
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: 0
Accepted
time: 0ms
memory: 3972kb
input:
6 7 1 2 2 3 3 4 4 5 5 6 1 6 3 6
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 3988kb
input:
33 36 2 22 12 18 27 28 9 19 26 27 6 21 15 16 2 3 7 24 3 12 4 23 28 29 5 14 29 30 1 10 11 13 6 13 16 25 14 21 4 16 10 19 10 11 5 15 1 8 3 20 7 13 25 26 29 31 17 23 8 18 12 24 25 30 31 32 17 20 15 22 9 18
output:
1
result:
wrong answer Answer contains longer sequence [length = 2], but output contains 1 elements