Submission #56087

# Submission time Handle Problem Language Result Execution time Memory
56087 2018-07-09T22:04:28 Z Benq Simurgh (IOI17_simurgh) C++14
70 / 100
803 ms 23908 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[30000]; // 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 2 ms 376 KB correct
2 Correct 3 ms 444 KB correct
3 Correct 3 ms 444 KB correct
4 Correct 3 ms 496 KB correct
5 Correct 3 ms 500 KB correct
6 Correct 2 ms 592 KB correct
7 Correct 2 ms 596 KB correct
8 Correct 2 ms 616 KB correct
9 Correct 2 ms 652 KB correct
10 Correct 2 ms 660 KB correct
11 Correct 2 ms 660 KB correct
12 Correct 2 ms 664 KB correct
13 Correct 2 ms 668 KB correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB correct
2 Correct 3 ms 444 KB correct
3 Correct 3 ms 444 KB correct
4 Correct 3 ms 496 KB correct
5 Correct 3 ms 500 KB correct
6 Correct 2 ms 592 KB correct
7 Correct 2 ms 596 KB correct
8 Correct 2 ms 616 KB correct
9 Correct 2 ms 652 KB correct
10 Correct 2 ms 660 KB correct
11 Correct 2 ms 660 KB correct
12 Correct 2 ms 664 KB correct
13 Correct 2 ms 668 KB correct
14 Correct 7 ms 904 KB correct
15 Correct 6 ms 904 KB correct
16 Correct 6 ms 904 KB correct
17 Correct 5 ms 904 KB correct
18 Correct 4 ms 904 KB correct
19 Correct 5 ms 908 KB correct
20 Correct 9 ms 908 KB correct
21 Correct 5 ms 992 KB correct
22 Correct 5 ms 992 KB correct
23 Correct 3 ms 992 KB correct
24 Correct 3 ms 992 KB correct
25 Correct 4 ms 992 KB correct
26 Correct 4 ms 992 KB correct
27 Correct 4 ms 992 KB correct
28 Correct 3 ms 992 KB correct
29 Correct 2 ms 992 KB correct
30 Correct 3 ms 992 KB correct
31 Correct 3 ms 992 KB correct
32 Correct 3 ms 992 KB correct
33 Correct 4 ms 992 KB correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB correct
2 Correct 3 ms 444 KB correct
3 Correct 3 ms 444 KB correct
4 Correct 3 ms 496 KB correct
5 Correct 3 ms 500 KB correct
6 Correct 2 ms 592 KB correct
7 Correct 2 ms 596 KB correct
8 Correct 2 ms 616 KB correct
9 Correct 2 ms 652 KB correct
10 Correct 2 ms 660 KB correct
11 Correct 2 ms 660 KB correct
12 Correct 2 ms 664 KB correct
13 Correct 2 ms 668 KB correct
14 Correct 7 ms 904 KB correct
15 Correct 6 ms 904 KB correct
16 Correct 6 ms 904 KB correct
17 Correct 5 ms 904 KB correct
18 Correct 4 ms 904 KB correct
19 Correct 5 ms 908 KB correct
20 Correct 9 ms 908 KB correct
21 Correct 5 ms 992 KB correct
22 Correct 5 ms 992 KB correct
23 Correct 3 ms 992 KB correct
24 Correct 3 ms 992 KB correct
25 Correct 4 ms 992 KB correct
26 Correct 4 ms 992 KB correct
27 Correct 4 ms 992 KB correct
28 Correct 3 ms 992 KB correct
29 Correct 2 ms 992 KB correct
30 Correct 3 ms 992 KB correct
31 Correct 3 ms 992 KB correct
32 Correct 3 ms 992 KB correct
33 Correct 4 ms 992 KB correct
34 Correct 89 ms 3120 KB correct
35 Correct 83 ms 3328 KB correct
36 Correct 62 ms 3328 KB correct
37 Correct 21 ms 3328 KB correct
38 Correct 89 ms 3664 KB correct
39 Correct 67 ms 3664 KB correct
40 Correct 64 ms 3664 KB correct
41 Correct 87 ms 4196 KB correct
42 Correct 92 ms 4388 KB correct
43 Correct 21 ms 4388 KB correct
44 Correct 20 ms 4388 KB correct
45 Correct 24 ms 4388 KB correct
46 Correct 15 ms 4388 KB correct
47 Correct 12 ms 4388 KB correct
48 Correct 9 ms 4388 KB correct
49 Correct 6 ms 4388 KB correct
50 Correct 10 ms 4388 KB correct
51 Correct 21 ms 4388 KB correct
52 Correct 17 ms 4388 KB correct
53 Correct 19 ms 4388 KB correct
54 Correct 18 ms 4388 KB correct
55 Correct 25 ms 4396 KB correct
56 Correct 18 ms 4396 KB correct
57 Correct 18 ms 4604 KB correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4604 KB correct
2 Correct 2 ms 4604 KB correct
3 Correct 317 ms 9752 KB correct
4 Correct 609 ms 13816 KB correct
5 Correct 584 ms 13816 KB correct
6 Correct 485 ms 13816 KB correct
7 Correct 462 ms 13816 KB correct
8 Correct 546 ms 13816 KB correct
9 Correct 492 ms 13924 KB correct
10 Correct 646 ms 13924 KB correct
11 Correct 681 ms 13924 KB correct
12 Correct 803 ms 13924 KB correct
13 Correct 3 ms 13924 KB correct
14 Correct 612 ms 13924 KB correct
15 Correct 540 ms 13924 KB correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB correct
2 Correct 3 ms 444 KB correct
3 Correct 3 ms 444 KB correct
4 Correct 3 ms 496 KB correct
5 Correct 3 ms 500 KB correct
6 Correct 2 ms 592 KB correct
7 Correct 2 ms 596 KB correct
8 Correct 2 ms 616 KB correct
9 Correct 2 ms 652 KB correct
10 Correct 2 ms 660 KB correct
11 Correct 2 ms 660 KB correct
12 Correct 2 ms 664 KB correct
13 Correct 2 ms 668 KB correct
14 Correct 7 ms 904 KB correct
15 Correct 6 ms 904 KB correct
16 Correct 6 ms 904 KB correct
17 Correct 5 ms 904 KB correct
18 Correct 4 ms 904 KB correct
19 Correct 5 ms 908 KB correct
20 Correct 9 ms 908 KB correct
21 Correct 5 ms 992 KB correct
22 Correct 5 ms 992 KB correct
23 Correct 3 ms 992 KB correct
24 Correct 3 ms 992 KB correct
25 Correct 4 ms 992 KB correct
26 Correct 4 ms 992 KB correct
27 Correct 4 ms 992 KB correct
28 Correct 3 ms 992 KB correct
29 Correct 2 ms 992 KB correct
30 Correct 3 ms 992 KB correct
31 Correct 3 ms 992 KB correct
32 Correct 3 ms 992 KB correct
33 Correct 4 ms 992 KB correct
34 Correct 89 ms 3120 KB correct
35 Correct 83 ms 3328 KB correct
36 Correct 62 ms 3328 KB correct
37 Correct 21 ms 3328 KB correct
38 Correct 89 ms 3664 KB correct
39 Correct 67 ms 3664 KB correct
40 Correct 64 ms 3664 KB correct
41 Correct 87 ms 4196 KB correct
42 Correct 92 ms 4388 KB correct
43 Correct 21 ms 4388 KB correct
44 Correct 20 ms 4388 KB correct
45 Correct 24 ms 4388 KB correct
46 Correct 15 ms 4388 KB correct
47 Correct 12 ms 4388 KB correct
48 Correct 9 ms 4388 KB correct
49 Correct 6 ms 4388 KB correct
50 Correct 10 ms 4388 KB correct
51 Correct 21 ms 4388 KB correct
52 Correct 17 ms 4388 KB correct
53 Correct 19 ms 4388 KB correct
54 Correct 18 ms 4388 KB correct
55 Correct 25 ms 4396 KB correct
56 Correct 18 ms 4396 KB correct
57 Correct 18 ms 4604 KB correct
58 Correct 2 ms 4604 KB correct
59 Correct 2 ms 4604 KB correct
60 Correct 317 ms 9752 KB correct
61 Correct 609 ms 13816 KB correct
62 Correct 584 ms 13816 KB correct
63 Correct 485 ms 13816 KB correct
64 Correct 462 ms 13816 KB correct
65 Correct 546 ms 13816 KB correct
66 Correct 492 ms 13924 KB correct
67 Correct 646 ms 13924 KB correct
68 Correct 681 ms 13924 KB correct
69 Correct 803 ms 13924 KB correct
70 Correct 3 ms 13924 KB correct
71 Correct 612 ms 13924 KB correct
72 Correct 540 ms 13924 KB correct
73 Correct 3 ms 13924 KB correct
74 Correct 646 ms 14808 KB correct
75 Correct 654 ms 15256 KB correct
76 Correct 232 ms 15256 KB correct
77 Correct 696 ms 16980 KB correct
78 Correct 626 ms 17728 KB correct
79 Correct 618 ms 18700 KB correct
80 Correct 450 ms 19368 KB correct
81 Correct 376 ms 19368 KB correct
82 Correct 448 ms 20896 KB correct
83 Correct 235 ms 20896 KB correct
84 Runtime error 86 ms 23908 KB Execution killed with signal 11 (could be triggered by violating memory limits)
85 Halted 0 ms 0 KB -