QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#374792 | #4686. Tours | zhaohaikun | WA | 4ms | 14004kb | C++20 | 1.7kb | 2024-04-02 18:18:37 | 2024-04-02 18:18:37 |
Judging History
answer
#include <bits/stdc++.h>
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T& x, T y) { x = max(x, y); }
template <typename T> inline void chkmin(T& x, T y) { x = min(x, y); }
template <typename T> inline void read(T &x) {
x = 0; int f = 1; char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= f;
}
const int N = 1e6 + 10;
int n, m, z[N], dep[N], fid[N];
ull val[N], vv[N], ans, ss[N], g;
mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
vector <pair <int, int>> v[N];
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
void dfs(int x, int fa) {
dep[x] = dep[fa] + 1;
for (auto [i, j]: v[x])
if (i != fa) {
if (!dep[i]) fid[i] = j, ss[i] = ss[x] + z[j], dfs(i, x), val[x] ^= val[i];
else {
if (dep[i] < dep[x]) {
vv[j] = mrand();
val[i] ^= vv[j];
val[x] ^= vv[j];
g = gcd(g, ss[x] - ss[i] + z[j]);
}
}
}
}
map <ull, ll> mp;
signed main() {
read(n), read(m);
F(i, 1, m) {
int x, y; read(x), read(y), z[i] = 1;
v[x].emplace_back(y, i);
v[y].emplace_back(x, i);
}
F(i, 1, n)
if (!dep[i]) dfs(i, 0);
F(i, 1, n) vv[fid[i]] = val[i];
F(i, 1, m)
if (vv[i]) mp[vv[i]] += z[i];//, cout << "~ " << vv[i] << endl;
// cout << g << endl;
for (auto [_, i]: mp) g = gcd(g, 2 * i);
F(i, 1, g)
if (g % i == 0) cout << i << ' ';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 14004kb
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: 3ms
memory: 13804kb
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: 13916kb
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: 13924kb
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: 13916kb
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