#include "simurgh.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int n0 = 503, m0 = 125000;
int N, M, used[n0], par[n0], ch[m0], same[m0], ep[m0];
int in[n0], out[n0], T, S;
vector <int> g[n0], V, U, query, back[n0];
set <int> st;
void add(int x) {
st.insert(x);
}
void del(int x) {
st.erase(x);
}
bool ex(int x) {
return st.find(x) != st.end();
}
int ask() {
query.clear();
for (int i : st) query.pb(i);
return count_common_roads(query);
}
void dfs(int v) {
used[v] = 1;
in[v] = ++T;
for (int i : g[v]) {
int to = V[i] ^ U[i] ^ v;
if (used[to]) continue;
par[to] = i;
add(i);
dfs(to);
}
out[v] = T;
}
bool upper(int x, int y) {
return in[x] <= in[y] && out[y] <= out[x];
}
bool cmp(const int & x, const int & y) {
if (x == y) return false;
return upper(ep[y], ep[x]);
}
int get(int v, int k) {
int u = v, res = S;
for (int i = 0; i <= k; i++) {
int j = back[v][i];
int to = V[j] ^ U[j] ^ v;
add(j), del(par[u]);
if (ch[par[u]] == 1) {
res--;
}
u = to;
}
res = ask() - res;
u = v;
for (int i = 0; i <= k; i++) {
int j = back[v][i];
int to = V[j] ^ U[j] ^ v;
del(j), add(par[u]);
u = to;
}
return res;
}
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
N = n, M = SZ(u), V = v, U = u;
for (int i = 0; i < M; i++)
g[v[i]].pb(i), g[u[i]].pb(i);
memset(& ch, -1, sizeof(ch));
par[0] = -1;
dfs(0);
vector <int> path;
S = ask();
for (int i = 0; i < M; i++) {
if (ex(i)) continue;
int a = v[i], b = u[i];
if (upper(b, a)) swap(a, b);
assert(upper(a, b));
int ok = 0;
path.clear();
while (b != a) {
path.pb(par[b]);
if (ch[par[b]] == -1) ok = 1;
b = v[par[b]] ^ u[par[b]] ^ b;
}
if (!ok) continue;
add(i);
for (int j : path) {
if (ch[i] != -1 && ch[j] != -1) continue;
del(j);
int x = ask();
if (x == S) {
same[j] = 1;
if (ch[j] != -1) ch[i] = ch[j];
} else if (x == S + 1) {
ch[i] = 1;
ch[j] = 0;
} else {
ch[i] = 0;
ch[j] = 1;
}
add(j);
}
del(i);
if (ch[i] == -1) ch[i] = 0;
for (int j : path) {
if (same[j]) ch[j] = ch[i];
same[j] = 0;
}
}
for (int i = 0; i < M; i++)
if (ex(i) && ch[i] == -1) ch[i] = 1;
for (int i = 0; i < N; i++) {
for (int j : g[i]) {
if (!ex(j)) {
int to = v[j] ^ u[j] ^ i;
if (upper(to, i)) {
ep[j] = to;
back[i].pb(j);
}
}
}
sort(all(back[i]), cmp);
int cur = -1, have = 0;
while (true) {
int l = cur, r = SZ(back[i]);
while (l < r - 1) {
int mid = l + r >> 1;
if (get(i, mid) > have) {
r = mid;
} else {
l = mid;
}
}
cur = r;
if (r < SZ(back[i])) {
ch[back[i][r]] = 1;
have++;
} else break;
}
}
vector <int> res;
for (int i = 0; i < M; i++) {
if (ch[i] == -1) ch[i] = 0;
if (ch[i] == 1) res.pb(i);
}
return res;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:146:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
896 KB |
correct |
2 |
Correct |
1 ms |
896 KB |
correct |
3 |
Correct |
1 ms |
896 KB |
correct |
4 |
Correct |
1 ms |
896 KB |
correct |
5 |
Correct |
1 ms |
896 KB |
correct |
6 |
Correct |
1 ms |
896 KB |
correct |
7 |
Correct |
1 ms |
896 KB |
correct |
8 |
Correct |
1 ms |
896 KB |
correct |
9 |
Correct |
1 ms |
896 KB |
correct |
10 |
Correct |
1 ms |
896 KB |
correct |
11 |
Correct |
1 ms |
792 KB |
correct |
12 |
Correct |
1 ms |
896 KB |
correct |
13 |
Correct |
1 ms |
896 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
896 KB |
correct |
2 |
Correct |
1 ms |
896 KB |
correct |
3 |
Correct |
1 ms |
896 KB |
correct |
4 |
Correct |
1 ms |
896 KB |
correct |
5 |
Correct |
1 ms |
896 KB |
correct |
6 |
Correct |
1 ms |
896 KB |
correct |
7 |
Correct |
1 ms |
896 KB |
correct |
8 |
Correct |
1 ms |
896 KB |
correct |
9 |
Correct |
1 ms |
896 KB |
correct |
10 |
Correct |
1 ms |
896 KB |
correct |
11 |
Correct |
1 ms |
792 KB |
correct |
12 |
Correct |
1 ms |
896 KB |
correct |
13 |
Correct |
1 ms |
896 KB |
correct |
14 |
Correct |
5 ms |
896 KB |
correct |
15 |
Correct |
6 ms |
896 KB |
correct |
16 |
Correct |
6 ms |
896 KB |
correct |
17 |
Correct |
4 ms |
896 KB |
correct |
18 |
Correct |
2 ms |
896 KB |
correct |
19 |
Correct |
4 ms |
896 KB |
correct |
20 |
Correct |
4 ms |
896 KB |
correct |
21 |
Correct |
4 ms |
896 KB |
correct |
22 |
Correct |
3 ms |
896 KB |
correct |
23 |
Correct |
2 ms |
896 KB |
correct |
24 |
Correct |
3 ms |
896 KB |
correct |
25 |
Correct |
1 ms |
896 KB |
correct |
26 |
Correct |
2 ms |
896 KB |
correct |
27 |
Correct |
3 ms |
896 KB |
correct |
28 |
Correct |
1 ms |
896 KB |
correct |
29 |
Correct |
1 ms |
896 KB |
correct |
30 |
Correct |
2 ms |
896 KB |
correct |
31 |
Correct |
3 ms |
896 KB |
correct |
32 |
Correct |
3 ms |
896 KB |
correct |
33 |
Correct |
3 ms |
896 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
896 KB |
correct |
2 |
Correct |
1 ms |
896 KB |
correct |
3 |
Correct |
1 ms |
896 KB |
correct |
4 |
Correct |
1 ms |
896 KB |
correct |
5 |
Correct |
1 ms |
896 KB |
correct |
6 |
Correct |
1 ms |
896 KB |
correct |
7 |
Correct |
1 ms |
896 KB |
correct |
8 |
Correct |
1 ms |
896 KB |
correct |
9 |
Correct |
1 ms |
896 KB |
correct |
10 |
Correct |
1 ms |
896 KB |
correct |
11 |
Correct |
1 ms |
792 KB |
correct |
12 |
Correct |
1 ms |
896 KB |
correct |
13 |
Correct |
1 ms |
896 KB |
correct |
14 |
Correct |
5 ms |
896 KB |
correct |
15 |
Correct |
6 ms |
896 KB |
correct |
16 |
Correct |
6 ms |
896 KB |
correct |
17 |
Correct |
4 ms |
896 KB |
correct |
18 |
Correct |
2 ms |
896 KB |
correct |
19 |
Correct |
4 ms |
896 KB |
correct |
20 |
Correct |
4 ms |
896 KB |
correct |
21 |
Correct |
4 ms |
896 KB |
correct |
22 |
Correct |
3 ms |
896 KB |
correct |
23 |
Correct |
2 ms |
896 KB |
correct |
24 |
Correct |
3 ms |
896 KB |
correct |
25 |
Correct |
1 ms |
896 KB |
correct |
26 |
Correct |
2 ms |
896 KB |
correct |
27 |
Correct |
3 ms |
896 KB |
correct |
28 |
Correct |
1 ms |
896 KB |
correct |
29 |
Correct |
1 ms |
896 KB |
correct |
30 |
Correct |
2 ms |
896 KB |
correct |
31 |
Correct |
3 ms |
896 KB |
correct |
32 |
Correct |
3 ms |
896 KB |
correct |
33 |
Correct |
3 ms |
896 KB |
correct |
34 |
Correct |
193 ms |
2356 KB |
correct |
35 |
Correct |
183 ms |
2296 KB |
correct |
36 |
Correct |
123 ms |
1912 KB |
correct |
37 |
Correct |
11 ms |
1024 KB |
correct |
38 |
Correct |
181 ms |
2296 KB |
correct |
39 |
Correct |
151 ms |
2168 KB |
correct |
40 |
Correct |
121 ms |
1956 KB |
correct |
41 |
Correct |
208 ms |
2300 KB |
correct |
42 |
Correct |
175 ms |
2296 KB |
correct |
43 |
Correct |
73 ms |
1664 KB |
correct |
44 |
Correct |
64 ms |
1528 KB |
correct |
45 |
Correct |
69 ms |
1656 KB |
correct |
46 |
Correct |
53 ms |
1468 KB |
correct |
47 |
Correct |
24 ms |
1152 KB |
correct |
48 |
Correct |
4 ms |
896 KB |
correct |
49 |
Correct |
10 ms |
896 KB |
correct |
50 |
Correct |
24 ms |
1152 KB |
correct |
51 |
Correct |
69 ms |
1568 KB |
correct |
52 |
Correct |
63 ms |
1528 KB |
correct |
53 |
Correct |
52 ms |
1408 KB |
correct |
54 |
Correct |
77 ms |
1784 KB |
correct |
55 |
Correct |
69 ms |
1528 KB |
correct |
56 |
Correct |
72 ms |
1588 KB |
correct |
57 |
Correct |
71 ms |
1656 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
896 KB |
correct |
2 |
Correct |
1 ms |
896 KB |
correct |
3 |
Correct |
638 ms |
5132 KB |
correct |
4 |
Correct |
1091 ms |
7160 KB |
correct |
5 |
Correct |
1092 ms |
7216 KB |
correct |
6 |
Correct |
1098 ms |
7032 KB |
correct |
7 |
Correct |
998 ms |
7012 KB |
correct |
8 |
Correct |
1058 ms |
7288 KB |
correct |
9 |
Correct |
1087 ms |
7268 KB |
correct |
10 |
Correct |
1093 ms |
7160 KB |
correct |
11 |
Correct |
1084 ms |
7160 KB |
correct |
12 |
Correct |
1096 ms |
7056 KB |
correct |
13 |
Correct |
1 ms |
896 KB |
correct |
14 |
Correct |
1062 ms |
7272 KB |
correct |
15 |
Correct |
1055 ms |
7160 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
896 KB |
correct |
2 |
Correct |
1 ms |
896 KB |
correct |
3 |
Correct |
1 ms |
896 KB |
correct |
4 |
Correct |
1 ms |
896 KB |
correct |
5 |
Correct |
1 ms |
896 KB |
correct |
6 |
Correct |
1 ms |
896 KB |
correct |
7 |
Correct |
1 ms |
896 KB |
correct |
8 |
Correct |
1 ms |
896 KB |
correct |
9 |
Correct |
1 ms |
896 KB |
correct |
10 |
Correct |
1 ms |
896 KB |
correct |
11 |
Correct |
1 ms |
792 KB |
correct |
12 |
Correct |
1 ms |
896 KB |
correct |
13 |
Correct |
1 ms |
896 KB |
correct |
14 |
Correct |
5 ms |
896 KB |
correct |
15 |
Correct |
6 ms |
896 KB |
correct |
16 |
Correct |
6 ms |
896 KB |
correct |
17 |
Correct |
4 ms |
896 KB |
correct |
18 |
Correct |
2 ms |
896 KB |
correct |
19 |
Correct |
4 ms |
896 KB |
correct |
20 |
Correct |
4 ms |
896 KB |
correct |
21 |
Correct |
4 ms |
896 KB |
correct |
22 |
Correct |
3 ms |
896 KB |
correct |
23 |
Correct |
2 ms |
896 KB |
correct |
24 |
Correct |
3 ms |
896 KB |
correct |
25 |
Correct |
1 ms |
896 KB |
correct |
26 |
Correct |
2 ms |
896 KB |
correct |
27 |
Correct |
3 ms |
896 KB |
correct |
28 |
Correct |
1 ms |
896 KB |
correct |
29 |
Correct |
1 ms |
896 KB |
correct |
30 |
Correct |
2 ms |
896 KB |
correct |
31 |
Correct |
3 ms |
896 KB |
correct |
32 |
Correct |
3 ms |
896 KB |
correct |
33 |
Correct |
3 ms |
896 KB |
correct |
34 |
Correct |
193 ms |
2356 KB |
correct |
35 |
Correct |
183 ms |
2296 KB |
correct |
36 |
Correct |
123 ms |
1912 KB |
correct |
37 |
Correct |
11 ms |
1024 KB |
correct |
38 |
Correct |
181 ms |
2296 KB |
correct |
39 |
Correct |
151 ms |
2168 KB |
correct |
40 |
Correct |
121 ms |
1956 KB |
correct |
41 |
Correct |
208 ms |
2300 KB |
correct |
42 |
Correct |
175 ms |
2296 KB |
correct |
43 |
Correct |
73 ms |
1664 KB |
correct |
44 |
Correct |
64 ms |
1528 KB |
correct |
45 |
Correct |
69 ms |
1656 KB |
correct |
46 |
Correct |
53 ms |
1468 KB |
correct |
47 |
Correct |
24 ms |
1152 KB |
correct |
48 |
Correct |
4 ms |
896 KB |
correct |
49 |
Correct |
10 ms |
896 KB |
correct |
50 |
Correct |
24 ms |
1152 KB |
correct |
51 |
Correct |
69 ms |
1568 KB |
correct |
52 |
Correct |
63 ms |
1528 KB |
correct |
53 |
Correct |
52 ms |
1408 KB |
correct |
54 |
Correct |
77 ms |
1784 KB |
correct |
55 |
Correct |
69 ms |
1528 KB |
correct |
56 |
Correct |
72 ms |
1588 KB |
correct |
57 |
Correct |
71 ms |
1656 KB |
correct |
58 |
Correct |
1 ms |
896 KB |
correct |
59 |
Correct |
1 ms |
896 KB |
correct |
60 |
Correct |
638 ms |
5132 KB |
correct |
61 |
Correct |
1091 ms |
7160 KB |
correct |
62 |
Correct |
1092 ms |
7216 KB |
correct |
63 |
Correct |
1098 ms |
7032 KB |
correct |
64 |
Correct |
998 ms |
7012 KB |
correct |
65 |
Correct |
1058 ms |
7288 KB |
correct |
66 |
Correct |
1087 ms |
7268 KB |
correct |
67 |
Correct |
1093 ms |
7160 KB |
correct |
68 |
Correct |
1084 ms |
7160 KB |
correct |
69 |
Correct |
1096 ms |
7056 KB |
correct |
70 |
Correct |
1 ms |
896 KB |
correct |
71 |
Correct |
1062 ms |
7272 KB |
correct |
72 |
Correct |
1055 ms |
7160 KB |
correct |
73 |
Correct |
1 ms |
896 KB |
correct |
74 |
Correct |
1097 ms |
7296 KB |
correct |
75 |
Correct |
1049 ms |
6924 KB |
correct |
76 |
Correct |
359 ms |
3292 KB |
correct |
77 |
Correct |
1094 ms |
7352 KB |
correct |
78 |
Correct |
1079 ms |
7008 KB |
correct |
79 |
Correct |
1062 ms |
7160 KB |
correct |
80 |
Correct |
1031 ms |
6976 KB |
correct |
81 |
Correct |
837 ms |
6264 KB |
correct |
82 |
Correct |
1031 ms |
6904 KB |
correct |
83 |
Correct |
506 ms |
4088 KB |
correct |
84 |
Correct |
480 ms |
4856 KB |
correct |
85 |
Correct |
414 ms |
4712 KB |
correct |
86 |
Correct |
282 ms |
3452 KB |
correct |
87 |
Correct |
201 ms |
2684 KB |
correct |
88 |
Correct |
157 ms |
2168 KB |
correct |
89 |
Correct |
156 ms |
2504 KB |
correct |
90 |
Correct |
130 ms |
1912 KB |
correct |
91 |
Correct |
31 ms |
1024 KB |
correct |
92 |
Correct |
14 ms |
896 KB |
correct |
93 |
Correct |
418 ms |
4472 KB |
correct |
94 |
Correct |
281 ms |
3324 KB |
correct |
95 |
Correct |
260 ms |
3192 KB |
correct |
96 |
Correct |
138 ms |
2040 KB |
correct |
97 |
Correct |
158 ms |
2168 KB |
correct |
98 |
Correct |
190 ms |
2680 KB |
correct |
99 |
Correct |
164 ms |
2296 KB |
correct |
100 |
Correct |
57 ms |
1272 KB |
correct |
101 |
Correct |
14 ms |
896 KB |
correct |
102 |
Correct |
400 ms |
3960 KB |
correct |
103 |
Correct |
405 ms |
4088 KB |
correct |
104 |
Correct |
391 ms |
3960 KB |
correct |
105 |
Correct |
400 ms |
3960 KB |
correct |