# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
56088 |
2018-07-09T22:06:30 Z |
Benq |
Simurgh (IOI17_simurgh) |
C++14 |
|
715 ms |
10596 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;
#include "simurgh.h"
template<int SZ> struct DSU {
int par[SZ], sz[SZ];
DSU() {
F0R(i,SZ) par[i] = i, sz[i] = 1;
}
int get(int x) { // path compression
if (par[x] != x) par[x] = get(par[x]);
return par[x];
}
bool unite(int x, int y) { // union-by-rank
x = get(x), y = get(y);
if (x == y) return 0;
if (sz[x] < sz[y]) swap(x,y);
sz[x] += sz[y], par[y] = x;
return 1;
}
};
int N;
vpi ed;
set<int> yes, maybe;
//////
/*int sec[500*499/2];
int co;
int count_common_roads(vi z) {
co ++;
// cout << "HA " << N << " " << sz(z) << "\n";
assert(sz(z) == N-1);
DSU<500> D = DSU<500>();
int ret = 0;
for (int i: z) {
if (!D.unite(ed[i].f,ed[i].s)) exit(5);
if (sec[i]) ret ++;
}
return ret;
}*/
//////
vpi ctree;
vpi adj[500];
pi par[500];
int depth[500], status[500*499/2]; // 1 = in, -1 = not
int query(vi x) {
DSU<500> D; for (int i: x) D.unite(ed[i].f,ed[i].s);
int ad = 0;
for (auto a: ctree) if (D.unite(ed[a.f].f,ed[a.f].s)) {
ad += a.s;
x.pb(a.f);
}
//cout << "OH " << sz(x) << "\n";
//return 0;
return count_common_roads(x)-ad;
}
void genDepth(int cur) {
depth[cur] = depth[par[cur].f]+1;
for (auto a: adj[cur]) if (a.f != par[cur].f) {
par[a.f] = {cur,a.s};
genDepth(a.f);
}
}
void check(int x) {
int a = ed[x].f, b = ed[x].s;
vi tmp = {x};
bool need = 0;
while (a != b) {
if (depth[a] < depth[b]) swap(a,b);
tmp.pb(par[a].s);
if (status[par[a].s] == 0) need = 1;
a = par[a].f;
}
if (!need || sz(tmp) == 2) return;
int mx = -MOD;
for (int i: tmp) if (status[i] != 0) {
vi v;
for (int j: tmp) if (j != i) v.pb(j);
mx = query(v);
if (status[i] == 1) mx ++;
break;
}
vpi TMP;
for (int i: tmp) if (status[i] == 0) {
vi v;
for (int j: tmp) if (j != i) v.pb(j);
int t = query(v);
mx = max(mx,t);
TMP.pb({t,i});
}
for (auto a: TMP) {
if (a.f < mx) {
status[a.s] = 1;
} else {
status[a.s] = -1;
}
}
}
void addEdge(int x) {
adj[ed[x].f].pb({ed[x].s,x});
adj[ed[x].s].pb({ed[x].f,x});
ctree.pb({x,0});
}
void init() {
DSU<500> D;
for (int i: maybe) if (D.unite(ed[i].f,ed[i].s)) addEdge(i);
genDepth(0);
for (int i: maybe) check(i);
for (auto& a: ctree) {
maybe.erase(a.f);
if (status[a.f] == 0) status[a.f] = 1;
a.s = (status[a.f]+1)/2;
if (a.s) yes.insert(a.f);
// cout << a.f << " " << a.s << "\n";
}
// exit(0);
}
void search(vi x, int num) {
/*for (int i: x) cout << i << " ";
cout << "\n";
cout << num << "\n";*/
if (num == 0) {
return;
}
if (num == sz(x)) {
for (int i: x) yes.insert(i);
return;
}
vi X = vi(x.begin(),x.begin()+sz(x)/2);
int n1 = query(X);
search(X,n1);
search(vi(x.begin()+sz(x)/2,x.end()),num-n1);
}
vector<int> find_roads(int n, vi u, vi v) {
yes.clear(), maybe.clear();
N = n;
ed.resize(sz(u));
F0R(i,sz(u)) {
ed[i].f = u[i], ed[i].s = v[i];
maybe.insert(i);
}
init();
while (sz(yes) < n-1) {
DSU<500> D;
vi tmp;
for (int x: maybe) if (D.unite(ed[x].f,ed[x].s)) tmp.pb(x);
for (int x: tmp) maybe.erase(x);
search(tmp, query(tmp));
}
vi ans; for (int i: yes) ans.pb(i);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
correct |
2 |
Correct |
3 ms |
376 KB |
correct |
3 |
Correct |
3 ms |
416 KB |
correct |
4 |
Correct |
2 ms |
496 KB |
correct |
5 |
Correct |
2 ms |
536 KB |
correct |
6 |
Correct |
2 ms |
544 KB |
correct |
7 |
Correct |
2 ms |
648 KB |
correct |
8 |
Correct |
2 ms |
648 KB |
correct |
9 |
Correct |
2 ms |
648 KB |
correct |
10 |
Correct |
3 ms |
648 KB |
correct |
11 |
Correct |
2 ms |
648 KB |
correct |
12 |
Correct |
2 ms |
648 KB |
correct |
13 |
Correct |
2 ms |
648 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
correct |
2 |
Correct |
3 ms |
376 KB |
correct |
3 |
Correct |
3 ms |
416 KB |
correct |
4 |
Correct |
2 ms |
496 KB |
correct |
5 |
Correct |
2 ms |
536 KB |
correct |
6 |
Correct |
2 ms |
544 KB |
correct |
7 |
Correct |
2 ms |
648 KB |
correct |
8 |
Correct |
2 ms |
648 KB |
correct |
9 |
Correct |
2 ms |
648 KB |
correct |
10 |
Correct |
3 ms |
648 KB |
correct |
11 |
Correct |
2 ms |
648 KB |
correct |
12 |
Correct |
2 ms |
648 KB |
correct |
13 |
Correct |
2 ms |
648 KB |
correct |
14 |
Correct |
5 ms |
648 KB |
correct |
15 |
Correct |
5 ms |
648 KB |
correct |
16 |
Correct |
5 ms |
748 KB |
correct |
17 |
Correct |
5 ms |
748 KB |
correct |
18 |
Correct |
3 ms |
748 KB |
correct |
19 |
Correct |
4 ms |
748 KB |
correct |
20 |
Correct |
5 ms |
748 KB |
correct |
21 |
Correct |
5 ms |
748 KB |
correct |
22 |
Correct |
4 ms |
748 KB |
correct |
23 |
Correct |
3 ms |
748 KB |
correct |
24 |
Correct |
3 ms |
748 KB |
correct |
25 |
Correct |
2 ms |
748 KB |
correct |
26 |
Correct |
3 ms |
748 KB |
correct |
27 |
Correct |
3 ms |
748 KB |
correct |
28 |
Correct |
3 ms |
748 KB |
correct |
29 |
Correct |
2 ms |
748 KB |
correct |
30 |
Correct |
3 ms |
748 KB |
correct |
31 |
Correct |
2 ms |
748 KB |
correct |
32 |
Correct |
3 ms |
748 KB |
correct |
33 |
Correct |
4 ms |
748 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
correct |
2 |
Correct |
3 ms |
376 KB |
correct |
3 |
Correct |
3 ms |
416 KB |
correct |
4 |
Correct |
2 ms |
496 KB |
correct |
5 |
Correct |
2 ms |
536 KB |
correct |
6 |
Correct |
2 ms |
544 KB |
correct |
7 |
Correct |
2 ms |
648 KB |
correct |
8 |
Correct |
2 ms |
648 KB |
correct |
9 |
Correct |
2 ms |
648 KB |
correct |
10 |
Correct |
3 ms |
648 KB |
correct |
11 |
Correct |
2 ms |
648 KB |
correct |
12 |
Correct |
2 ms |
648 KB |
correct |
13 |
Correct |
2 ms |
648 KB |
correct |
14 |
Correct |
5 ms |
648 KB |
correct |
15 |
Correct |
5 ms |
648 KB |
correct |
16 |
Correct |
5 ms |
748 KB |
correct |
17 |
Correct |
5 ms |
748 KB |
correct |
18 |
Correct |
3 ms |
748 KB |
correct |
19 |
Correct |
4 ms |
748 KB |
correct |
20 |
Correct |
5 ms |
748 KB |
correct |
21 |
Correct |
5 ms |
748 KB |
correct |
22 |
Correct |
4 ms |
748 KB |
correct |
23 |
Correct |
3 ms |
748 KB |
correct |
24 |
Correct |
3 ms |
748 KB |
correct |
25 |
Correct |
2 ms |
748 KB |
correct |
26 |
Correct |
3 ms |
748 KB |
correct |
27 |
Correct |
3 ms |
748 KB |
correct |
28 |
Correct |
3 ms |
748 KB |
correct |
29 |
Correct |
2 ms |
748 KB |
correct |
30 |
Correct |
3 ms |
748 KB |
correct |
31 |
Correct |
2 ms |
748 KB |
correct |
32 |
Correct |
3 ms |
748 KB |
correct |
33 |
Correct |
4 ms |
748 KB |
correct |
34 |
Correct |
106 ms |
2688 KB |
correct |
35 |
Correct |
104 ms |
2688 KB |
correct |
36 |
Correct |
67 ms |
2688 KB |
correct |
37 |
Correct |
16 ms |
2688 KB |
correct |
38 |
Correct |
90 ms |
2688 KB |
correct |
39 |
Correct |
79 ms |
2688 KB |
correct |
40 |
Correct |
75 ms |
2688 KB |
correct |
41 |
Correct |
91 ms |
2688 KB |
correct |
42 |
Correct |
97 ms |
2688 KB |
correct |
43 |
Correct |
18 ms |
2688 KB |
correct |
44 |
Correct |
15 ms |
2688 KB |
correct |
45 |
Correct |
18 ms |
2688 KB |
correct |
46 |
Correct |
14 ms |
2688 KB |
correct |
47 |
Correct |
11 ms |
2688 KB |
correct |
48 |
Correct |
4 ms |
2688 KB |
correct |
49 |
Correct |
6 ms |
2688 KB |
correct |
50 |
Correct |
9 ms |
2688 KB |
correct |
51 |
Correct |
20 ms |
2688 KB |
correct |
52 |
Correct |
15 ms |
2688 KB |
correct |
53 |
Correct |
14 ms |
2688 KB |
correct |
54 |
Correct |
24 ms |
2688 KB |
correct |
55 |
Correct |
18 ms |
2688 KB |
correct |
56 |
Correct |
19 ms |
2688 KB |
correct |
57 |
Correct |
24 ms |
2688 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
correct |
2 |
Correct |
3 ms |
2688 KB |
correct |
3 |
Correct |
450 ms |
6396 KB |
correct |
4 |
Correct |
702 ms |
9468 KB |
correct |
5 |
Correct |
715 ms |
9468 KB |
correct |
6 |
Correct |
681 ms |
9468 KB |
correct |
7 |
Correct |
619 ms |
9536 KB |
correct |
8 |
Correct |
638 ms |
9536 KB |
correct |
9 |
Correct |
620 ms |
9536 KB |
correct |
10 |
Correct |
686 ms |
9596 KB |
correct |
11 |
Correct |
601 ms |
9596 KB |
correct |
12 |
Correct |
599 ms |
9600 KB |
correct |
13 |
Correct |
2 ms |
9600 KB |
correct |
14 |
Correct |
676 ms |
9600 KB |
correct |
15 |
Correct |
623 ms |
9600 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
correct |
2 |
Correct |
3 ms |
376 KB |
correct |
3 |
Correct |
3 ms |
416 KB |
correct |
4 |
Correct |
2 ms |
496 KB |
correct |
5 |
Correct |
2 ms |
536 KB |
correct |
6 |
Correct |
2 ms |
544 KB |
correct |
7 |
Correct |
2 ms |
648 KB |
correct |
8 |
Correct |
2 ms |
648 KB |
correct |
9 |
Correct |
2 ms |
648 KB |
correct |
10 |
Correct |
3 ms |
648 KB |
correct |
11 |
Correct |
2 ms |
648 KB |
correct |
12 |
Correct |
2 ms |
648 KB |
correct |
13 |
Correct |
2 ms |
648 KB |
correct |
14 |
Correct |
5 ms |
648 KB |
correct |
15 |
Correct |
5 ms |
648 KB |
correct |
16 |
Correct |
5 ms |
748 KB |
correct |
17 |
Correct |
5 ms |
748 KB |
correct |
18 |
Correct |
3 ms |
748 KB |
correct |
19 |
Correct |
4 ms |
748 KB |
correct |
20 |
Correct |
5 ms |
748 KB |
correct |
21 |
Correct |
5 ms |
748 KB |
correct |
22 |
Correct |
4 ms |
748 KB |
correct |
23 |
Correct |
3 ms |
748 KB |
correct |
24 |
Correct |
3 ms |
748 KB |
correct |
25 |
Correct |
2 ms |
748 KB |
correct |
26 |
Correct |
3 ms |
748 KB |
correct |
27 |
Correct |
3 ms |
748 KB |
correct |
28 |
Correct |
3 ms |
748 KB |
correct |
29 |
Correct |
2 ms |
748 KB |
correct |
30 |
Correct |
3 ms |
748 KB |
correct |
31 |
Correct |
2 ms |
748 KB |
correct |
32 |
Correct |
3 ms |
748 KB |
correct |
33 |
Correct |
4 ms |
748 KB |
correct |
34 |
Correct |
106 ms |
2688 KB |
correct |
35 |
Correct |
104 ms |
2688 KB |
correct |
36 |
Correct |
67 ms |
2688 KB |
correct |
37 |
Correct |
16 ms |
2688 KB |
correct |
38 |
Correct |
90 ms |
2688 KB |
correct |
39 |
Correct |
79 ms |
2688 KB |
correct |
40 |
Correct |
75 ms |
2688 KB |
correct |
41 |
Correct |
91 ms |
2688 KB |
correct |
42 |
Correct |
97 ms |
2688 KB |
correct |
43 |
Correct |
18 ms |
2688 KB |
correct |
44 |
Correct |
15 ms |
2688 KB |
correct |
45 |
Correct |
18 ms |
2688 KB |
correct |
46 |
Correct |
14 ms |
2688 KB |
correct |
47 |
Correct |
11 ms |
2688 KB |
correct |
48 |
Correct |
4 ms |
2688 KB |
correct |
49 |
Correct |
6 ms |
2688 KB |
correct |
50 |
Correct |
9 ms |
2688 KB |
correct |
51 |
Correct |
20 ms |
2688 KB |
correct |
52 |
Correct |
15 ms |
2688 KB |
correct |
53 |
Correct |
14 ms |
2688 KB |
correct |
54 |
Correct |
24 ms |
2688 KB |
correct |
55 |
Correct |
18 ms |
2688 KB |
correct |
56 |
Correct |
19 ms |
2688 KB |
correct |
57 |
Correct |
24 ms |
2688 KB |
correct |
58 |
Correct |
2 ms |
2688 KB |
correct |
59 |
Correct |
3 ms |
2688 KB |
correct |
60 |
Correct |
450 ms |
6396 KB |
correct |
61 |
Correct |
702 ms |
9468 KB |
correct |
62 |
Correct |
715 ms |
9468 KB |
correct |
63 |
Correct |
681 ms |
9468 KB |
correct |
64 |
Correct |
619 ms |
9536 KB |
correct |
65 |
Correct |
638 ms |
9536 KB |
correct |
66 |
Correct |
620 ms |
9536 KB |
correct |
67 |
Correct |
686 ms |
9596 KB |
correct |
68 |
Correct |
601 ms |
9596 KB |
correct |
69 |
Correct |
599 ms |
9600 KB |
correct |
70 |
Correct |
2 ms |
9600 KB |
correct |
71 |
Correct |
676 ms |
9600 KB |
correct |
72 |
Correct |
623 ms |
9600 KB |
correct |
73 |
Correct |
2 ms |
9600 KB |
correct |
74 |
Correct |
647 ms |
9608 KB |
correct |
75 |
Correct |
697 ms |
9608 KB |
correct |
76 |
Correct |
153 ms |
9608 KB |
correct |
77 |
Correct |
487 ms |
9608 KB |
correct |
78 |
Correct |
532 ms |
9608 KB |
correct |
79 |
Correct |
629 ms |
9608 KB |
correct |
80 |
Correct |
671 ms |
9608 KB |
correct |
81 |
Correct |
437 ms |
9608 KB |
correct |
82 |
Correct |
673 ms |
9608 KB |
correct |
83 |
Correct |
246 ms |
9608 KB |
correct |
84 |
Correct |
92 ms |
9608 KB |
correct |
85 |
Correct |
93 ms |
9608 KB |
correct |
86 |
Correct |
57 ms |
9608 KB |
correct |
87 |
Correct |
46 ms |
9608 KB |
correct |
88 |
Correct |
38 ms |
9608 KB |
correct |
89 |
Correct |
37 ms |
9608 KB |
correct |
90 |
Correct |
33 ms |
9608 KB |
correct |
91 |
Correct |
15 ms |
9608 KB |
correct |
92 |
Correct |
11 ms |
9608 KB |
correct |
93 |
Correct |
78 ms |
9608 KB |
correct |
94 |
Correct |
56 ms |
9608 KB |
correct |
95 |
Correct |
69 ms |
9608 KB |
correct |
96 |
Correct |
40 ms |
9608 KB |
correct |
97 |
Correct |
42 ms |
9608 KB |
correct |
98 |
Correct |
51 ms |
9608 KB |
correct |
99 |
Correct |
43 ms |
9608 KB |
correct |
100 |
Correct |
36 ms |
9608 KB |
correct |
101 |
Correct |
17 ms |
9608 KB |
correct |
102 |
Correct |
86 ms |
9608 KB |
correct |
103 |
Correct |
103 ms |
9640 KB |
correct |
104 |
Correct |
86 ms |
10232 KB |
correct |
105 |
Correct |
92 ms |
10596 KB |
correct |