# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
108911 |
2019-05-02T15:01:14 Z |
Noam527 |
Simurgh (IOI17_simurgh) |
C++17 |
|
339 ms |
6648 KB |
#include <bits/stdc++.h>
#define CHECK cout << "ok" << endl
#define finish(x) return cout << x << endl, 0
typedef long long ll;
typedef long double ldb;
const int md = 1e9 + 7;
const ll inf = 1e18;
const int OO = 0;
const int OOO = 1;
using namespace std;
int count_common_roads(const vector<int>& r);
int ask(const vector<int> &r) {
return count_common_roads(r);
}
struct edge {
int to, i;
edge() {}
edge(int tt, int ii) {
to = tt;
i = ii;
}
};
struct dsu {
int n;
vector<int> p, r;
dsu() {}
dsu(int sz) {
n = sz;
p.resize(n);
r.resize(n);
clear();
}
void clear() {
for (int i = 0; i < n; i++) {
p[i] = i;
r[i] = 0;
}
}
int find(int x) {
return x == p[x] ? x : p[x] = find(p[x]);
}
bool unite(int x, int y) {
x = find(x), y = find(y);
if (x == y) return false;
if (r[x] < r[y]) p[x] = y;
else {
p[y] = x;
if (r[x] == r[y]) r[x]++;
}
return true;
}
};
const int mxn = 505, mxm = 125000;
int n, m;
vector<edge> g[mxn];
int vis[mxn], par[mxn], pare[mxn];
int dep[mxn];
vector<int> tree;
int org;
int value[mxm];
void dfs(int v = 0, int d = 0) {
vis[v] = 1;
dep[v] = d;
for (const auto &i : g[v])
if (!vis[i.to]) {
par[i.to] = v;
pare[i.to] = i.i;
tree[i.to - 1] = i.i;
dfs(i.to, 1 + d);
}
}
void process(pair<int, int> aa, int i) {
int u = aa.first, v = aa.second, vv, tmp;
if (dep[u] > dep[v]) swap(u, v);
vv = v;
if (tree[v - 1] == i) return;
bool found = false;
int good = -1;
while (vv != u) {
if (value[pare[vv]] == -1) {
found = true;
break;
}
vv = par[vv];
}
if (OO) cout << "processing edge " << u << " " << v << ", " << found << '\n';
if (!found) return;
vv = v;
while (vv != u) {
if (value[pare[vv]] != -1) {
good = vv;
break;
}
vv = par[vv];
}
int curedge;
if (good == -1) {
vv = v;
found = false;
while (vv != u) {
swap(tree[vv - 1], i);
int x = ask(tree);
swap(tree[vv - 1], i);
if (x != org) {
found = true;
if (x < org) curedge = 0;
else curedge = 1;
break;
}
vv = par[vv];
}
if (!found) curedge = 0;
}
else {
swap(tree[good - 1], i);
int x = ask(tree);
swap(tree[good - 1], i);
if (x < org) curedge = 0;
else if (x > org) curedge = 1;
else curedge = value[pare[vv]];
}
if (OO) cout << "curedge " << curedge << '\n';
vv = v;
while (vv != u) {
if (value[pare[vv]] == -1) {
swap(tree[vv - 1], i);
int x = ask(tree);
swap(tree[vv - 1], i);
if (x < org) value[pare[vv]] = 1;
else if (x > org) value[pare[vv]] = 0;
else value[pare[vv]] = curedge;
if (OO) {
cout << "so, value of " << pare[vv] << " is " << value[pare[vv]] << '\n';
}
}
vv = par[vv];
}
}
dsu ds;
vector<int> rr;
int query(int s, int pre) {
ds.clear();
int nxt = 0;
for (int i = 0; i < pre; i++) {
ds.unite(s, g[s][i].to);
rr[nxt++] = g[s][i].i;
}
int ans = 0;
for (int i = 1; i < n; i++)
if (ds.unite(i, par[i])) {
ans -= value[tree[i - 1]];
rr[nxt++] = tree[i - 1];
}
//if (OO) cout << "query " << s << " " << pre << ", ans " << ans << '\n';
return ans + ask(rr);
}
vector<int> calc(int s) {
vector<int> rtn;
int tot = query(s, g[s].size());
if (OO) cout << "calc " << s << ", tot " << tot << '\n';
int lo = 1, hi = (int)g[s].size(), mid;
for (int i = 1; i <= tot; i++) {
hi = (int)g[s].size();
while (lo < hi) {
mid = (lo + hi) / 2;
if (query(s, mid) < i) lo = mid + 1;
else hi = mid;
}
if (OO) cout << "edge " << i << " is " << s << ", " << g[s][lo - 1].to << ", index " << g[s][lo - 1].i << '\n';
rtn.push_back(g[s][lo - 1].i);
}
return rtn;
}
vector<int> find_roads(int N, vector<int> u, vector<int> v) {
n = N;
m = u.size();
tree.resize(n - 1);
ds = dsu(n);
rr.resize(n - 1);
for (int i = 0; i < m; i++) {
g[u[i]].push_back(edge(v[i], i));
g[v[i]].push_back(edge(u[i], i));
value[i] = -1;
}
dfs();
if (OO) {
cout << "my spanning tree\n";
for (const auto &i : tree) cout << i << " "; cout << '\n';
cout << "par: ";
for (const auto &i : tree) cout << par[i] << " "; cout << '\n';
cout << "par: ";
for (const auto &i : tree) cout << pare[i] << " "; cout << '\n';
}
org = ask(tree);
for (int i = 0; i < m; i++) {
process(make_pair(u[i], v[i]), i);
}
for (const auto &i : tree)
if (value[i] == -1) value[i] = 1; // bridge
if (OO) {
cout << "my spanning tree\n";
for (const auto &i : tree) cout << i << " "; cout << '\n';
cout << "with values\n";
for (const auto &i : tree) cout << value[i] << " "; cout << '\n';
}
vector<int> tmp, ans(m, 0);
for (int i = 0; i < n; i++) {
tmp = calc(i);
for (const auto &j : tmp) ans[j] = 1;
}
tmp.clear();
for (int i = 0; i < m; i++)
if (ans[i])
tmp.push_back(i);
return tmp;
}
Compilation message
simurgh.cpp: In function 'void process(std::pair<int, int>, int)':
simurgh.cpp:80:39: warning: unused variable 'tmp' [-Wunused-variable]
int u = aa.first, v = aa.second, vv, tmp;
^~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:199:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (const auto &i : tree) cout << i << " "; cout << '\n';
^~~
simurgh.cpp:199:48: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for (const auto &i : tree) cout << i << " "; cout << '\n';
^~~~
simurgh.cpp:201:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (const auto &i : tree) cout << par[i] << " "; cout << '\n';
^~~
simurgh.cpp:201:53: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for (const auto &i : tree) cout << par[i] << " "; cout << '\n';
^~~~
simurgh.cpp:203:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (const auto &i : tree) cout << pare[i] << " "; cout << '\n';
^~~
simurgh.cpp:203:54: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for (const auto &i : tree) cout << pare[i] << " "; cout << '\n';
^~~~
simurgh.cpp:213:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (const auto &i : tree) cout << i << " "; cout << '\n';
^~~
simurgh.cpp:213:48: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for (const auto &i : tree) cout << i << " "; cout << '\n';
^~~~
simurgh.cpp:215:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (const auto &i : tree) cout << value[i] << " "; cout << '\n';
^~~
simurgh.cpp:215:55: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for (const auto &i : tree) cout << value[i] << " "; cout << '\n';
^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
correct |
2 |
Correct |
3 ms |
384 KB |
correct |
3 |
Correct |
2 ms |
384 KB |
correct |
4 |
Correct |
2 ms |
384 KB |
correct |
5 |
Correct |
2 ms |
384 KB |
correct |
6 |
Correct |
2 ms |
384 KB |
correct |
7 |
Correct |
2 ms |
384 KB |
correct |
8 |
Correct |
2 ms |
384 KB |
correct |
9 |
Correct |
2 ms |
384 KB |
correct |
10 |
Correct |
2 ms |
384 KB |
correct |
11 |
Correct |
3 ms |
384 KB |
correct |
12 |
Correct |
2 ms |
384 KB |
correct |
13 |
Correct |
2 ms |
384 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
correct |
2 |
Correct |
3 ms |
384 KB |
correct |
3 |
Correct |
2 ms |
384 KB |
correct |
4 |
Correct |
2 ms |
384 KB |
correct |
5 |
Correct |
2 ms |
384 KB |
correct |
6 |
Correct |
2 ms |
384 KB |
correct |
7 |
Correct |
2 ms |
384 KB |
correct |
8 |
Correct |
2 ms |
384 KB |
correct |
9 |
Correct |
2 ms |
384 KB |
correct |
10 |
Correct |
2 ms |
384 KB |
correct |
11 |
Correct |
3 ms |
384 KB |
correct |
12 |
Correct |
2 ms |
384 KB |
correct |
13 |
Correct |
2 ms |
384 KB |
correct |
14 |
Correct |
4 ms |
384 KB |
correct |
15 |
Correct |
4 ms |
432 KB |
correct |
16 |
Correct |
4 ms |
384 KB |
correct |
17 |
Correct |
4 ms |
384 KB |
correct |
18 |
Correct |
3 ms |
384 KB |
correct |
19 |
Correct |
4 ms |
384 KB |
correct |
20 |
Correct |
2 ms |
384 KB |
correct |
21 |
Correct |
4 ms |
384 KB |
correct |
22 |
Correct |
4 ms |
384 KB |
correct |
23 |
Correct |
3 ms |
384 KB |
correct |
24 |
Correct |
1 ms |
384 KB |
correct |
25 |
Correct |
3 ms |
384 KB |
correct |
26 |
Correct |
4 ms |
512 KB |
correct |
27 |
Correct |
4 ms |
384 KB |
correct |
28 |
Correct |
4 ms |
384 KB |
correct |
29 |
Correct |
4 ms |
384 KB |
correct |
30 |
Correct |
4 ms |
384 KB |
correct |
31 |
Correct |
4 ms |
384 KB |
correct |
32 |
Correct |
4 ms |
512 KB |
correct |
33 |
Correct |
4 ms |
384 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
correct |
2 |
Correct |
3 ms |
384 KB |
correct |
3 |
Correct |
2 ms |
384 KB |
correct |
4 |
Correct |
2 ms |
384 KB |
correct |
5 |
Correct |
2 ms |
384 KB |
correct |
6 |
Correct |
2 ms |
384 KB |
correct |
7 |
Correct |
2 ms |
384 KB |
correct |
8 |
Correct |
2 ms |
384 KB |
correct |
9 |
Correct |
2 ms |
384 KB |
correct |
10 |
Correct |
2 ms |
384 KB |
correct |
11 |
Correct |
3 ms |
384 KB |
correct |
12 |
Correct |
2 ms |
384 KB |
correct |
13 |
Correct |
2 ms |
384 KB |
correct |
14 |
Correct |
4 ms |
384 KB |
correct |
15 |
Correct |
4 ms |
432 KB |
correct |
16 |
Correct |
4 ms |
384 KB |
correct |
17 |
Correct |
4 ms |
384 KB |
correct |
18 |
Correct |
3 ms |
384 KB |
correct |
19 |
Correct |
4 ms |
384 KB |
correct |
20 |
Correct |
2 ms |
384 KB |
correct |
21 |
Correct |
4 ms |
384 KB |
correct |
22 |
Correct |
4 ms |
384 KB |
correct |
23 |
Correct |
3 ms |
384 KB |
correct |
24 |
Correct |
1 ms |
384 KB |
correct |
25 |
Correct |
3 ms |
384 KB |
correct |
26 |
Correct |
4 ms |
512 KB |
correct |
27 |
Correct |
4 ms |
384 KB |
correct |
28 |
Correct |
4 ms |
384 KB |
correct |
29 |
Correct |
4 ms |
384 KB |
correct |
30 |
Correct |
4 ms |
384 KB |
correct |
31 |
Correct |
4 ms |
384 KB |
correct |
32 |
Correct |
4 ms |
512 KB |
correct |
33 |
Correct |
4 ms |
384 KB |
correct |
34 |
Correct |
55 ms |
1776 KB |
correct |
35 |
Correct |
54 ms |
1784 KB |
correct |
36 |
Correct |
61 ms |
1408 KB |
correct |
37 |
Correct |
15 ms |
512 KB |
correct |
38 |
Correct |
50 ms |
1792 KB |
correct |
39 |
Correct |
51 ms |
1664 KB |
correct |
40 |
Correct |
46 ms |
1408 KB |
correct |
41 |
Correct |
47 ms |
1792 KB |
correct |
42 |
Correct |
48 ms |
1912 KB |
correct |
43 |
Correct |
41 ms |
1280 KB |
correct |
44 |
Correct |
40 ms |
1024 KB |
correct |
45 |
Correct |
34 ms |
1024 KB |
correct |
46 |
Correct |
36 ms |
896 KB |
correct |
47 |
Correct |
26 ms |
640 KB |
correct |
48 |
Correct |
8 ms |
384 KB |
correct |
49 |
Correct |
17 ms |
384 KB |
correct |
50 |
Correct |
26 ms |
640 KB |
correct |
51 |
Correct |
37 ms |
1024 KB |
correct |
52 |
Correct |
36 ms |
956 KB |
correct |
53 |
Correct |
38 ms |
896 KB |
correct |
54 |
Correct |
42 ms |
1276 KB |
correct |
55 |
Correct |
47 ms |
1024 KB |
correct |
56 |
Correct |
46 ms |
1112 KB |
correct |
57 |
Correct |
42 ms |
1152 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
correct |
2 |
Correct |
2 ms |
384 KB |
correct |
3 |
Correct |
210 ms |
4444 KB |
correct |
4 |
Correct |
324 ms |
5880 KB |
correct |
5 |
Correct |
299 ms |
5880 KB |
correct |
6 |
Correct |
279 ms |
5752 KB |
correct |
7 |
Correct |
286 ms |
5880 KB |
correct |
8 |
Correct |
306 ms |
5924 KB |
correct |
9 |
Correct |
333 ms |
5880 KB |
correct |
10 |
Correct |
339 ms |
5880 KB |
correct |
11 |
Correct |
315 ms |
5892 KB |
correct |
12 |
Correct |
286 ms |
5900 KB |
correct |
13 |
Correct |
2 ms |
384 KB |
correct |
14 |
Correct |
297 ms |
6624 KB |
correct |
15 |
Correct |
309 ms |
6648 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
correct |
2 |
Correct |
3 ms |
384 KB |
correct |
3 |
Correct |
2 ms |
384 KB |
correct |
4 |
Correct |
2 ms |
384 KB |
correct |
5 |
Correct |
2 ms |
384 KB |
correct |
6 |
Correct |
2 ms |
384 KB |
correct |
7 |
Correct |
2 ms |
384 KB |
correct |
8 |
Correct |
2 ms |
384 KB |
correct |
9 |
Correct |
2 ms |
384 KB |
correct |
10 |
Correct |
2 ms |
384 KB |
correct |
11 |
Correct |
3 ms |
384 KB |
correct |
12 |
Correct |
2 ms |
384 KB |
correct |
13 |
Correct |
2 ms |
384 KB |
correct |
14 |
Correct |
4 ms |
384 KB |
correct |
15 |
Correct |
4 ms |
432 KB |
correct |
16 |
Correct |
4 ms |
384 KB |
correct |
17 |
Correct |
4 ms |
384 KB |
correct |
18 |
Correct |
3 ms |
384 KB |
correct |
19 |
Correct |
4 ms |
384 KB |
correct |
20 |
Correct |
2 ms |
384 KB |
correct |
21 |
Correct |
4 ms |
384 KB |
correct |
22 |
Correct |
4 ms |
384 KB |
correct |
23 |
Correct |
3 ms |
384 KB |
correct |
24 |
Correct |
1 ms |
384 KB |
correct |
25 |
Correct |
3 ms |
384 KB |
correct |
26 |
Correct |
4 ms |
512 KB |
correct |
27 |
Correct |
4 ms |
384 KB |
correct |
28 |
Correct |
4 ms |
384 KB |
correct |
29 |
Correct |
4 ms |
384 KB |
correct |
30 |
Correct |
4 ms |
384 KB |
correct |
31 |
Correct |
4 ms |
384 KB |
correct |
32 |
Correct |
4 ms |
512 KB |
correct |
33 |
Correct |
4 ms |
384 KB |
correct |
34 |
Correct |
55 ms |
1776 KB |
correct |
35 |
Correct |
54 ms |
1784 KB |
correct |
36 |
Correct |
61 ms |
1408 KB |
correct |
37 |
Correct |
15 ms |
512 KB |
correct |
38 |
Correct |
50 ms |
1792 KB |
correct |
39 |
Correct |
51 ms |
1664 KB |
correct |
40 |
Correct |
46 ms |
1408 KB |
correct |
41 |
Correct |
47 ms |
1792 KB |
correct |
42 |
Correct |
48 ms |
1912 KB |
correct |
43 |
Correct |
41 ms |
1280 KB |
correct |
44 |
Correct |
40 ms |
1024 KB |
correct |
45 |
Correct |
34 ms |
1024 KB |
correct |
46 |
Correct |
36 ms |
896 KB |
correct |
47 |
Correct |
26 ms |
640 KB |
correct |
48 |
Correct |
8 ms |
384 KB |
correct |
49 |
Correct |
17 ms |
384 KB |
correct |
50 |
Correct |
26 ms |
640 KB |
correct |
51 |
Correct |
37 ms |
1024 KB |
correct |
52 |
Correct |
36 ms |
956 KB |
correct |
53 |
Correct |
38 ms |
896 KB |
correct |
54 |
Correct |
42 ms |
1276 KB |
correct |
55 |
Correct |
47 ms |
1024 KB |
correct |
56 |
Correct |
46 ms |
1112 KB |
correct |
57 |
Correct |
42 ms |
1152 KB |
correct |
58 |
Correct |
2 ms |
384 KB |
correct |
59 |
Correct |
2 ms |
384 KB |
correct |
60 |
Correct |
210 ms |
4444 KB |
correct |
61 |
Correct |
324 ms |
5880 KB |
correct |
62 |
Correct |
299 ms |
5880 KB |
correct |
63 |
Correct |
279 ms |
5752 KB |
correct |
64 |
Correct |
286 ms |
5880 KB |
correct |
65 |
Correct |
306 ms |
5924 KB |
correct |
66 |
Correct |
333 ms |
5880 KB |
correct |
67 |
Correct |
339 ms |
5880 KB |
correct |
68 |
Correct |
315 ms |
5892 KB |
correct |
69 |
Correct |
286 ms |
5900 KB |
correct |
70 |
Correct |
2 ms |
384 KB |
correct |
71 |
Correct |
297 ms |
6624 KB |
correct |
72 |
Correct |
309 ms |
6648 KB |
correct |
73 |
Correct |
2 ms |
384 KB |
correct |
74 |
Incorrect |
279 ms |
6516 KB |
WA in grader: NO |
75 |
Halted |
0 ms |
0 KB |
- |