#include <bits/stdc++.h>
#include "simurgh.h"
//#include "Lgrader.cpp"
using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 9);
const int MAXM = (1 << 18);
struct dsu
{
int par[MAXN], sz[MAXN];
void init(int n)
{
for(int i = 0; i <= n; i++)
par[i] = i, sz[i] = 1;
}
int root(int x) { return par[x] == x ? x : par[x] = root(par[x]); }
bool connected(int x, int y) { return root(x) == root(y); }
void unite(int u, int v)
{
u = root(u);
v = root(v);
if(u == v) return;
if(sz[u] < sz[v]) swap(u, v);
par[v] = u;
sz[u] += sz[v];
}
} d;
int m, n;
pair<int, int> ed[MAXM];
vector<pair<int, int> > adj[MAXN];
int dfs_time, low[MAXN], disc[MAXN];
int low_edge[MAXN], ver[MAXN];
int E[MAXM];
int par[MAXN], pe[MAXN];
vector<int> li[MAXM];
vector<int> le, Tr;
bool cmp(int i, int j) { return min(low[ed[i].first], low[ed[i].second]) < min(low[ed[j].first], low[ed[j].second]); }
void tarjan(int u, int pr)
{
low[u] = disc[u] = ++dfs_time;
ver[dfs_time] = u;
low_edge[u] = -1;
for(auto e: adj[u])
if(e.first != pr)
{
int v = e.first;
if(!disc[v])
{
par[v] = u;
pe[v] = e.second;
tarjan(v, u);
if(chkmin(low[u], low[v]))
low_edge[u] = low_edge[v];
if(disc[u] < low[v])
E[e.second] = 1;
}
else if(chkmin(low[u], disc[v]))
low_edge[u] = e.second;
}
if(low_edge[u] != -1)
le.push_back(low_edge[u]);
if(u != pr) Tr.push_back(pe[u]);
}
int R[MAXM];
int initial;
int diff(int rem, int add)
{
vector<int> tmp;
for(int e: Tr)
if(e == rem) tmp.push_back(add);
else tmp.push_back(e);
return count_common_roads(tmp) - initial;
}
int cnt_good(vector<int> L)
{
d.init(::n);
vector<int> tmp = L;
for(int i: L)
d.unite(ed[i].first, ed[i].second);
int to_rem = 0;
for(int i: Tr)
if(!d.connected(ed[i].first, ed[i].second))
to_rem += E[i], d.unite(ed[i].first, ed[i].second), tmp.push_back(i);
return count_common_roads(tmp) - to_rem;
}
void rec(vector<int> &l, int sum)
{
if(sum == 0)
return;
if(l.size() == 1)
{
E[l.back()] = 1;
return;
}
vector<int> m1, m2;
for(int i = 0; i < (int)l.size() / 2; i++) m1.push_back(l[i]);
for(int i = l.size() / 2; i < (int)l.size(); i++) m2.push_back(l[i]);
int c1 = cnt_good(m1), c2 = sum - c1;
rec(m1, c1);
rec(m2, c2);
}
std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v)
{
::n = n;
::m = u.size();
for(int i = 0; i < ::m; i++)
{
ed[i] = {u[i], v[i]};
adj[u[i]].push_back({v[i], i});
adj[v[i]].push_back({u[i], i});
E[i] = -1;
}
tarjan(0, 0);
sort(le.begin(), le.end());
le.erase(unique(le.begin(), le.end()), le.end());
sort(le.begin(), le.end(), cmp);
initial = count_common_roads(Tr);
for(int i: le)
{
int from = ed[i].first, to = ed[i].second;
if(disc[from] > disc[to]) swap(from, to);
while(to != from)
{
li[i].push_back(pe[to]);
to = par[to];
}
int has = -1;
for(int e: li[i])
if(E[e] != -1)
has = e;
if(has != -1)
{
int df = diff(has, i);
if(df == 0) E[i] = E[has];
else E[i] = E[has] ^ 1;
for(int e: li[i])
if(E[e] == -1)
{
int df = diff(e, i);
if(df == 0) E[e] = E[i];
else E[e] = E[i] ^ 1;
}
}
else
{
bool fl = 0;
for(int e: li[i])
{
R[e] = diff(e, i);
if(R[e]) fl = 1;
}
if(!fl)
{
E[i] = 0;
for(int e: li[i])
E[e] = 0;
}
else
{
for(int e: li[i])
if(R[e])
{
if(R[e] == 1) E[i] = 1;
else E[i] = 0;
break;
}
for(int e: li[i])
if(E[e] == -1)
{
int df = R[e];
if(df == 0) E[e] = E[i];
else E[e] = E[i] ^ 1;
}
}
}
}
for(int i = 0; i < n; i++)
{
int cnt = 0;
vector<int> candidates;
for(auto e: adj[i])
if(E[e.second] == -1)
candidates.push_back(e.second);
cnt = cnt_good(candidates);
rec(candidates, cnt);
}
vector<int> result;
for(int i = 0; i < ::m; i++)
if(E[i] == 1)
result.push_back(i);
return result;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
6520 KB |
correct |
2 |
Correct |
7 ms |
6520 KB |
correct |
3 |
Correct |
9 ms |
6572 KB |
correct |
4 |
Correct |
7 ms |
6572 KB |
correct |
5 |
Correct |
7 ms |
6572 KB |
correct |
6 |
Correct |
8 ms |
6632 KB |
correct |
7 |
Correct |
8 ms |
6664 KB |
correct |
8 |
Correct |
7 ms |
6664 KB |
correct |
9 |
Correct |
8 ms |
6792 KB |
correct |
10 |
Correct |
8 ms |
6792 KB |
correct |
11 |
Correct |
8 ms |
6792 KB |
correct |
12 |
Correct |
7 ms |
6792 KB |
correct |
13 |
Correct |
8 ms |
6856 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
6520 KB |
correct |
2 |
Correct |
7 ms |
6520 KB |
correct |
3 |
Correct |
9 ms |
6572 KB |
correct |
4 |
Correct |
7 ms |
6572 KB |
correct |
5 |
Correct |
7 ms |
6572 KB |
correct |
6 |
Correct |
8 ms |
6632 KB |
correct |
7 |
Correct |
8 ms |
6664 KB |
correct |
8 |
Correct |
7 ms |
6664 KB |
correct |
9 |
Correct |
8 ms |
6792 KB |
correct |
10 |
Correct |
8 ms |
6792 KB |
correct |
11 |
Correct |
8 ms |
6792 KB |
correct |
12 |
Correct |
7 ms |
6792 KB |
correct |
13 |
Correct |
8 ms |
6856 KB |
correct |
14 |
Correct |
10 ms |
6856 KB |
correct |
15 |
Correct |
7 ms |
6864 KB |
correct |
16 |
Correct |
9 ms |
6864 KB |
correct |
17 |
Correct |
8 ms |
6864 KB |
correct |
18 |
Correct |
8 ms |
6864 KB |
correct |
19 |
Correct |
8 ms |
6864 KB |
correct |
20 |
Correct |
8 ms |
6864 KB |
correct |
21 |
Correct |
11 ms |
6864 KB |
correct |
22 |
Correct |
9 ms |
6864 KB |
correct |
23 |
Correct |
8 ms |
6864 KB |
correct |
24 |
Correct |
8 ms |
6864 KB |
correct |
25 |
Correct |
9 ms |
6864 KB |
correct |
26 |
Correct |
8 ms |
6864 KB |
correct |
27 |
Correct |
9 ms |
6864 KB |
correct |
28 |
Correct |
8 ms |
6864 KB |
correct |
29 |
Correct |
10 ms |
6864 KB |
correct |
30 |
Correct |
8 ms |
6864 KB |
correct |
31 |
Correct |
9 ms |
6864 KB |
correct |
32 |
Correct |
9 ms |
6864 KB |
correct |
33 |
Correct |
8 ms |
6864 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
6520 KB |
correct |
2 |
Correct |
7 ms |
6520 KB |
correct |
3 |
Correct |
9 ms |
6572 KB |
correct |
4 |
Correct |
7 ms |
6572 KB |
correct |
5 |
Correct |
7 ms |
6572 KB |
correct |
6 |
Correct |
8 ms |
6632 KB |
correct |
7 |
Correct |
8 ms |
6664 KB |
correct |
8 |
Correct |
7 ms |
6664 KB |
correct |
9 |
Correct |
8 ms |
6792 KB |
correct |
10 |
Correct |
8 ms |
6792 KB |
correct |
11 |
Correct |
8 ms |
6792 KB |
correct |
12 |
Correct |
7 ms |
6792 KB |
correct |
13 |
Correct |
8 ms |
6856 KB |
correct |
14 |
Correct |
10 ms |
6856 KB |
correct |
15 |
Correct |
7 ms |
6864 KB |
correct |
16 |
Correct |
9 ms |
6864 KB |
correct |
17 |
Correct |
8 ms |
6864 KB |
correct |
18 |
Correct |
8 ms |
6864 KB |
correct |
19 |
Correct |
8 ms |
6864 KB |
correct |
20 |
Correct |
8 ms |
6864 KB |
correct |
21 |
Correct |
11 ms |
6864 KB |
correct |
22 |
Correct |
9 ms |
6864 KB |
correct |
23 |
Correct |
8 ms |
6864 KB |
correct |
24 |
Correct |
8 ms |
6864 KB |
correct |
25 |
Correct |
9 ms |
6864 KB |
correct |
26 |
Correct |
8 ms |
6864 KB |
correct |
27 |
Correct |
9 ms |
6864 KB |
correct |
28 |
Correct |
8 ms |
6864 KB |
correct |
29 |
Correct |
10 ms |
6864 KB |
correct |
30 |
Correct |
8 ms |
6864 KB |
correct |
31 |
Correct |
9 ms |
6864 KB |
correct |
32 |
Correct |
9 ms |
6864 KB |
correct |
33 |
Correct |
8 ms |
6864 KB |
correct |
34 |
Correct |
48 ms |
8060 KB |
correct |
35 |
Correct |
41 ms |
8060 KB |
correct |
36 |
Correct |
35 ms |
8060 KB |
correct |
37 |
Correct |
22 ms |
8060 KB |
correct |
38 |
Correct |
40 ms |
8060 KB |
correct |
39 |
Correct |
33 ms |
8060 KB |
correct |
40 |
Correct |
30 ms |
8060 KB |
correct |
41 |
Correct |
38 ms |
8060 KB |
correct |
42 |
Correct |
40 ms |
8104 KB |
correct |
43 |
Correct |
22 ms |
8104 KB |
correct |
44 |
Correct |
29 ms |
8104 KB |
correct |
45 |
Correct |
22 ms |
8104 KB |
correct |
46 |
Correct |
21 ms |
8104 KB |
correct |
47 |
Correct |
16 ms |
8104 KB |
correct |
48 |
Correct |
10 ms |
8104 KB |
correct |
49 |
Correct |
13 ms |
8104 KB |
correct |
50 |
Correct |
15 ms |
8104 KB |
correct |
51 |
Correct |
22 ms |
8104 KB |
correct |
52 |
Correct |
20 ms |
8104 KB |
correct |
53 |
Correct |
20 ms |
8104 KB |
correct |
54 |
Correct |
22 ms |
8104 KB |
correct |
55 |
Correct |
20 ms |
8104 KB |
correct |
56 |
Correct |
20 ms |
8104 KB |
correct |
57 |
Correct |
19 ms |
8104 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8104 KB |
correct |
2 |
Correct |
9 ms |
8104 KB |
correct |
3 |
Correct |
116 ms |
10876 KB |
correct |
4 |
Correct |
154 ms |
12540 KB |
correct |
5 |
Correct |
166 ms |
12540 KB |
correct |
6 |
Correct |
151 ms |
12540 KB |
correct |
7 |
Correct |
122 ms |
12540 KB |
correct |
8 |
Correct |
114 ms |
12540 KB |
correct |
9 |
Correct |
152 ms |
12540 KB |
correct |
10 |
Correct |
171 ms |
12540 KB |
correct |
11 |
Correct |
165 ms |
12540 KB |
correct |
12 |
Correct |
205 ms |
12540 KB |
correct |
13 |
Correct |
7 ms |
12540 KB |
correct |
14 |
Correct |
142 ms |
12540 KB |
correct |
15 |
Correct |
165 ms |
12548 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
6520 KB |
correct |
2 |
Correct |
7 ms |
6520 KB |
correct |
3 |
Correct |
9 ms |
6572 KB |
correct |
4 |
Correct |
7 ms |
6572 KB |
correct |
5 |
Correct |
7 ms |
6572 KB |
correct |
6 |
Correct |
8 ms |
6632 KB |
correct |
7 |
Correct |
8 ms |
6664 KB |
correct |
8 |
Correct |
7 ms |
6664 KB |
correct |
9 |
Correct |
8 ms |
6792 KB |
correct |
10 |
Correct |
8 ms |
6792 KB |
correct |
11 |
Correct |
8 ms |
6792 KB |
correct |
12 |
Correct |
7 ms |
6792 KB |
correct |
13 |
Correct |
8 ms |
6856 KB |
correct |
14 |
Correct |
10 ms |
6856 KB |
correct |
15 |
Correct |
7 ms |
6864 KB |
correct |
16 |
Correct |
9 ms |
6864 KB |
correct |
17 |
Correct |
8 ms |
6864 KB |
correct |
18 |
Correct |
8 ms |
6864 KB |
correct |
19 |
Correct |
8 ms |
6864 KB |
correct |
20 |
Correct |
8 ms |
6864 KB |
correct |
21 |
Correct |
11 ms |
6864 KB |
correct |
22 |
Correct |
9 ms |
6864 KB |
correct |
23 |
Correct |
8 ms |
6864 KB |
correct |
24 |
Correct |
8 ms |
6864 KB |
correct |
25 |
Correct |
9 ms |
6864 KB |
correct |
26 |
Correct |
8 ms |
6864 KB |
correct |
27 |
Correct |
9 ms |
6864 KB |
correct |
28 |
Correct |
8 ms |
6864 KB |
correct |
29 |
Correct |
10 ms |
6864 KB |
correct |
30 |
Correct |
8 ms |
6864 KB |
correct |
31 |
Correct |
9 ms |
6864 KB |
correct |
32 |
Correct |
9 ms |
6864 KB |
correct |
33 |
Correct |
8 ms |
6864 KB |
correct |
34 |
Correct |
48 ms |
8060 KB |
correct |
35 |
Correct |
41 ms |
8060 KB |
correct |
36 |
Correct |
35 ms |
8060 KB |
correct |
37 |
Correct |
22 ms |
8060 KB |
correct |
38 |
Correct |
40 ms |
8060 KB |
correct |
39 |
Correct |
33 ms |
8060 KB |
correct |
40 |
Correct |
30 ms |
8060 KB |
correct |
41 |
Correct |
38 ms |
8060 KB |
correct |
42 |
Correct |
40 ms |
8104 KB |
correct |
43 |
Correct |
22 ms |
8104 KB |
correct |
44 |
Correct |
29 ms |
8104 KB |
correct |
45 |
Correct |
22 ms |
8104 KB |
correct |
46 |
Correct |
21 ms |
8104 KB |
correct |
47 |
Correct |
16 ms |
8104 KB |
correct |
48 |
Correct |
10 ms |
8104 KB |
correct |
49 |
Correct |
13 ms |
8104 KB |
correct |
50 |
Correct |
15 ms |
8104 KB |
correct |
51 |
Correct |
22 ms |
8104 KB |
correct |
52 |
Correct |
20 ms |
8104 KB |
correct |
53 |
Correct |
20 ms |
8104 KB |
correct |
54 |
Correct |
22 ms |
8104 KB |
correct |
55 |
Correct |
20 ms |
8104 KB |
correct |
56 |
Correct |
20 ms |
8104 KB |
correct |
57 |
Correct |
19 ms |
8104 KB |
correct |
58 |
Correct |
7 ms |
8104 KB |
correct |
59 |
Correct |
9 ms |
8104 KB |
correct |
60 |
Correct |
116 ms |
10876 KB |
correct |
61 |
Correct |
154 ms |
12540 KB |
correct |
62 |
Correct |
166 ms |
12540 KB |
correct |
63 |
Correct |
151 ms |
12540 KB |
correct |
64 |
Correct |
122 ms |
12540 KB |
correct |
65 |
Correct |
114 ms |
12540 KB |
correct |
66 |
Correct |
152 ms |
12540 KB |
correct |
67 |
Correct |
171 ms |
12540 KB |
correct |
68 |
Correct |
165 ms |
12540 KB |
correct |
69 |
Correct |
205 ms |
12540 KB |
correct |
70 |
Correct |
7 ms |
12540 KB |
correct |
71 |
Correct |
142 ms |
12540 KB |
correct |
72 |
Correct |
165 ms |
12548 KB |
correct |
73 |
Correct |
7 ms |
12548 KB |
correct |
74 |
Correct |
168 ms |
12548 KB |
correct |
75 |
Correct |
159 ms |
12548 KB |
correct |
76 |
Correct |
79 ms |
12548 KB |
correct |
77 |
Correct |
156 ms |
12548 KB |
correct |
78 |
Correct |
157 ms |
12548 KB |
correct |
79 |
Correct |
157 ms |
12548 KB |
correct |
80 |
Correct |
155 ms |
12548 KB |
correct |
81 |
Correct |
108 ms |
12548 KB |
correct |
82 |
Correct |
159 ms |
12548 KB |
correct |
83 |
Correct |
118 ms |
12548 KB |
correct |
84 |
Correct |
75 ms |
12548 KB |
correct |
85 |
Correct |
90 ms |
12548 KB |
correct |
86 |
Correct |
55 ms |
12548 KB |
correct |
87 |
Correct |
58 ms |
12548 KB |
correct |
88 |
Correct |
46 ms |
12548 KB |
correct |
89 |
Correct |
45 ms |
12548 KB |
correct |
90 |
Correct |
40 ms |
12548 KB |
correct |
91 |
Correct |
34 ms |
12548 KB |
correct |
92 |
Correct |
24 ms |
12548 KB |
correct |
93 |
Correct |
83 ms |
12548 KB |
correct |
94 |
Correct |
64 ms |
12548 KB |
correct |
95 |
Correct |
69 ms |
12548 KB |
correct |
96 |
Correct |
46 ms |
12548 KB |
correct |
97 |
Correct |
45 ms |
12548 KB |
correct |
98 |
Correct |
49 ms |
12548 KB |
correct |
99 |
Correct |
44 ms |
12548 KB |
correct |
100 |
Correct |
29 ms |
12548 KB |
correct |
101 |
Correct |
19 ms |
12548 KB |
correct |
102 |
Correct |
73 ms |
12548 KB |
correct |
103 |
Correct |
69 ms |
12548 KB |
correct |
104 |
Correct |
67 ms |
12548 KB |
correct |
105 |
Correct |
90 ms |
12548 KB |
correct |