#include <bits/stdc++.h>
#include "simurgh.h"
using namespace std;
using ll = long long;
ll n, m, q, k, x, y, a, b, c;
vector<ll> G[500];
struct dsu {
ll n;
vector<ll> par;
vector<ll> sz;
dsu(ll N) : n(N) {
par.resize(n);
sz.resize(n);
for (int i = 0; i < n; i++) {
par[i] = i;
sz[i] = 1;
}
}
ll find_p(ll x) {
if (par[x] == x) {
return x;
}
ll p = find_p(par[x]);
par[x] = p;
return p;
}
void join(ll x, ll y) {
x = find_p(x);
y = find_p(y);
if (x == y) {
return;
}
if (sz[y] > sz[x]) {
swap(x, y);
}
par[y] = x;
sz[x] += sz[y];
}
};
vector<int> find_roads(int N, vector<int> u, vector<int> v) {
mt19937 gen(chrono::system_clock::now().time_since_epoch().count());
n = N;
m = u.size();
vector< pair< pair<ll, ll>, ll > > vp(m);
for (int i = 0; i < m; i++) {
vp[i].first = {u[i], v[i]};
vp[i].second = i;
G[u[i]].push_back(v[i]);
G[v[i]].push_back(u[i]);
}
map<int, int> ans;
for (int i = 0; i < n; i++) {
// cout << i << endl;
for (int j = 0; j < m; j++) {
swap(vp[j], vp[gen() % (j + 1)]);
}
dsu d(n);
set<ll> st1, st2;
vector<int> e;
for (int j = 0; j < m; j++) {
if (vp[j].first.first == i || vp[j].first.second == i) {
if (ans.count(vp[j].second)) {
st2.insert(vp[j].second);
}
else {
st1.insert(vp[j].second);
}
continue;
}
if (d.find_p(vp[j].first.first) != d.find_p(vp[j].first.second)) {
d.join(vp[j].first.first, vp[j].first.second);
e.push_back(vp[j].second);
}
}
if (st1.size() == 0) {
continue;
}
// cout << st1.size() << ' ' << st2.size() << endl;
set<ll> st;
map<ll, ll> to;
for (int j = 0; j < n; j++) {
if (i == j) {
continue;
}
st.insert(d.find_p(j));
}
ll cnt = 0;
for (auto j : st) {
to[j] = cnt++;
}
vector< vector<ll> > v1(cnt), v2(cnt);
for (int j : st1) {
v1[to[d.find_p(v[j] != i ? v[j] : u[j])]].push_back(j);
}
for (int j : st2) {
v2[to[d.find_p(v[j] != i ? v[j] : u[j])]].push_back(j);
}
for (int j = cnt - 1; j >= 0; j--) {
e.push_back((v1[j].size() == 0) ? v2[j][0] : v1[j][0]);
}
reverse(e.begin(), e.end());
// cout << "DEBUG" << endl;
for (int i = 0; i < cnt; i++) {
// cout << v1[i].size() << ' ' << v2[i].size() << '\n';
if (v1[i].size() == 0) {
continue;
}
map< ll, vector<ll> > mp;
for (int j : v1[i]) {
e[i] = j;
mp[count_common_roads(e)].push_back(j);
}
if (mp.size() == 1) {
if (v2[i].size() == 0) {
for (auto j : (*mp.begin()).second) {
ans[j] = 1;
}
}
else {
// cout << "DEBUG" << endl;
e[i] = v2[i][0];
ll x = count_common_roads(e);
for (auto j : mp) {
// cout << '\t' << j.first << ' ' << x << '\n';
for (auto k : j.second) {
// cout << "\t\t" << k << '\t';
if (j.first == x) {
ans[k] = ans[v2[i][0]];
}
else {
ans[k] = 1 - ans[v2[i][0]];
}
// cout << "\t\t" << ans[k] << '\n';
}
}
}
}
else {
for (auto i : (*mp.begin()).second) {
ans[i] = 0;
}
for (auto i : (*++mp.begin()).second) {
ans[i] = 1;
}
}
e[i] = ((v1[i].size() == 0) ? v2[i][0] : v1[i][0]);
}
}
vector<int> ansv;
for (int i = 0; i < m; i++) {
if (ans[i] == 1) {
ansv.push_back(i);
// cout << i << ' ';
}
}
// cout << '\n';
return ansv;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
correct |
2 |
Correct |
0 ms |
344 KB |
correct |
3 |
Correct |
1 ms |
348 KB |
correct |
4 |
Correct |
0 ms |
344 KB |
correct |
5 |
Correct |
0 ms |
348 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
344 KB |
correct |
8 |
Correct |
1 ms |
348 KB |
correct |
9 |
Correct |
0 ms |
348 KB |
correct |
10 |
Correct |
1 ms |
348 KB |
correct |
11 |
Correct |
1 ms |
348 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
correct |
2 |
Correct |
0 ms |
344 KB |
correct |
3 |
Correct |
1 ms |
348 KB |
correct |
4 |
Correct |
0 ms |
344 KB |
correct |
5 |
Correct |
0 ms |
348 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
344 KB |
correct |
8 |
Correct |
1 ms |
348 KB |
correct |
9 |
Correct |
0 ms |
348 KB |
correct |
10 |
Correct |
1 ms |
348 KB |
correct |
11 |
Correct |
1 ms |
348 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
14 |
Correct |
4 ms |
604 KB |
correct |
15 |
Correct |
3 ms |
600 KB |
correct |
16 |
Correct |
3 ms |
348 KB |
correct |
17 |
Correct |
2 ms |
348 KB |
correct |
18 |
Correct |
1 ms |
348 KB |
correct |
19 |
Correct |
3 ms |
348 KB |
correct |
20 |
Correct |
2 ms |
540 KB |
correct |
21 |
Correct |
2 ms |
348 KB |
correct |
22 |
Correct |
2 ms |
344 KB |
correct |
23 |
Correct |
2 ms |
348 KB |
correct |
24 |
Correct |
2 ms |
440 KB |
correct |
25 |
Correct |
1 ms |
348 KB |
correct |
26 |
Correct |
2 ms |
348 KB |
correct |
27 |
Correct |
1 ms |
348 KB |
correct |
28 |
Correct |
1 ms |
348 KB |
correct |
29 |
Correct |
1 ms |
348 KB |
correct |
30 |
Correct |
2 ms |
348 KB |
correct |
31 |
Correct |
2 ms |
348 KB |
correct |
32 |
Correct |
2 ms |
348 KB |
correct |
33 |
Correct |
3 ms |
348 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
correct |
2 |
Correct |
0 ms |
344 KB |
correct |
3 |
Correct |
1 ms |
348 KB |
correct |
4 |
Correct |
0 ms |
344 KB |
correct |
5 |
Correct |
0 ms |
348 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
344 KB |
correct |
8 |
Correct |
1 ms |
348 KB |
correct |
9 |
Correct |
0 ms |
348 KB |
correct |
10 |
Correct |
1 ms |
348 KB |
correct |
11 |
Correct |
1 ms |
348 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
14 |
Correct |
4 ms |
604 KB |
correct |
15 |
Correct |
3 ms |
600 KB |
correct |
16 |
Correct |
3 ms |
348 KB |
correct |
17 |
Correct |
2 ms |
348 KB |
correct |
18 |
Correct |
1 ms |
348 KB |
correct |
19 |
Correct |
3 ms |
348 KB |
correct |
20 |
Correct |
2 ms |
540 KB |
correct |
21 |
Correct |
2 ms |
348 KB |
correct |
22 |
Correct |
2 ms |
344 KB |
correct |
23 |
Correct |
2 ms |
348 KB |
correct |
24 |
Correct |
2 ms |
440 KB |
correct |
25 |
Correct |
1 ms |
348 KB |
correct |
26 |
Correct |
2 ms |
348 KB |
correct |
27 |
Correct |
1 ms |
348 KB |
correct |
28 |
Correct |
1 ms |
348 KB |
correct |
29 |
Correct |
1 ms |
348 KB |
correct |
30 |
Correct |
2 ms |
348 KB |
correct |
31 |
Correct |
2 ms |
348 KB |
correct |
32 |
Correct |
2 ms |
348 KB |
correct |
33 |
Correct |
3 ms |
348 KB |
correct |
34 |
Correct |
185 ms |
3408 KB |
correct |
35 |
Correct |
178 ms |
3544 KB |
correct |
36 |
Correct |
133 ms |
2780 KB |
correct |
37 |
Correct |
9 ms |
344 KB |
correct |
38 |
Correct |
177 ms |
3632 KB |
correct |
39 |
Correct |
151 ms |
3156 KB |
correct |
40 |
Correct |
126 ms |
2644 KB |
correct |
41 |
Correct |
189 ms |
3428 KB |
correct |
42 |
Correct |
172 ms |
3552 KB |
correct |
43 |
Correct |
92 ms |
2188 KB |
correct |
44 |
Correct |
83 ms |
1644 KB |
correct |
45 |
Correct |
89 ms |
2032 KB |
correct |
46 |
Correct |
71 ms |
1588 KB |
correct |
47 |
Correct |
30 ms |
860 KB |
correct |
48 |
Correct |
5 ms |
344 KB |
correct |
49 |
Correct |
13 ms |
604 KB |
correct |
50 |
Correct |
36 ms |
980 KB |
correct |
51 |
Correct |
86 ms |
1988 KB |
correct |
52 |
Correct |
78 ms |
1740 KB |
correct |
53 |
Correct |
95 ms |
1492 KB |
correct |
54 |
Correct |
114 ms |
2204 KB |
correct |
55 |
Correct |
100 ms |
1828 KB |
correct |
56 |
Correct |
87 ms |
1972 KB |
correct |
57 |
Correct |
101 ms |
1876 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
correct |
2 |
Correct |
1 ms |
348 KB |
correct |
3 |
Incorrect |
96 ms |
5676 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
correct |
2 |
Correct |
0 ms |
344 KB |
correct |
3 |
Correct |
1 ms |
348 KB |
correct |
4 |
Correct |
0 ms |
344 KB |
correct |
5 |
Correct |
0 ms |
348 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
344 KB |
correct |
8 |
Correct |
1 ms |
348 KB |
correct |
9 |
Correct |
0 ms |
348 KB |
correct |
10 |
Correct |
1 ms |
348 KB |
correct |
11 |
Correct |
1 ms |
348 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
14 |
Correct |
4 ms |
604 KB |
correct |
15 |
Correct |
3 ms |
600 KB |
correct |
16 |
Correct |
3 ms |
348 KB |
correct |
17 |
Correct |
2 ms |
348 KB |
correct |
18 |
Correct |
1 ms |
348 KB |
correct |
19 |
Correct |
3 ms |
348 KB |
correct |
20 |
Correct |
2 ms |
540 KB |
correct |
21 |
Correct |
2 ms |
348 KB |
correct |
22 |
Correct |
2 ms |
344 KB |
correct |
23 |
Correct |
2 ms |
348 KB |
correct |
24 |
Correct |
2 ms |
440 KB |
correct |
25 |
Correct |
1 ms |
348 KB |
correct |
26 |
Correct |
2 ms |
348 KB |
correct |
27 |
Correct |
1 ms |
348 KB |
correct |
28 |
Correct |
1 ms |
348 KB |
correct |
29 |
Correct |
1 ms |
348 KB |
correct |
30 |
Correct |
2 ms |
348 KB |
correct |
31 |
Correct |
2 ms |
348 KB |
correct |
32 |
Correct |
2 ms |
348 KB |
correct |
33 |
Correct |
3 ms |
348 KB |
correct |
34 |
Correct |
185 ms |
3408 KB |
correct |
35 |
Correct |
178 ms |
3544 KB |
correct |
36 |
Correct |
133 ms |
2780 KB |
correct |
37 |
Correct |
9 ms |
344 KB |
correct |
38 |
Correct |
177 ms |
3632 KB |
correct |
39 |
Correct |
151 ms |
3156 KB |
correct |
40 |
Correct |
126 ms |
2644 KB |
correct |
41 |
Correct |
189 ms |
3428 KB |
correct |
42 |
Correct |
172 ms |
3552 KB |
correct |
43 |
Correct |
92 ms |
2188 KB |
correct |
44 |
Correct |
83 ms |
1644 KB |
correct |
45 |
Correct |
89 ms |
2032 KB |
correct |
46 |
Correct |
71 ms |
1588 KB |
correct |
47 |
Correct |
30 ms |
860 KB |
correct |
48 |
Correct |
5 ms |
344 KB |
correct |
49 |
Correct |
13 ms |
604 KB |
correct |
50 |
Correct |
36 ms |
980 KB |
correct |
51 |
Correct |
86 ms |
1988 KB |
correct |
52 |
Correct |
78 ms |
1740 KB |
correct |
53 |
Correct |
95 ms |
1492 KB |
correct |
54 |
Correct |
114 ms |
2204 KB |
correct |
55 |
Correct |
100 ms |
1828 KB |
correct |
56 |
Correct |
87 ms |
1972 KB |
correct |
57 |
Correct |
101 ms |
1876 KB |
correct |
58 |
Correct |
0 ms |
344 KB |
correct |
59 |
Correct |
1 ms |
348 KB |
correct |
60 |
Incorrect |
96 ms |
5676 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |