Submission #372282

# Submission time Handle Problem Language Result Execution time Memory
372282 2021-02-27T13:42:22 Z doowey Simurgh (IOI17_simurgh) C++14
51 / 100
161 ms 7404 KB
#include <bits/stdc++.h>
#include "simurgh.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair

const int N = 500;
const int M = N * (N - 1) / 2;
vector<pii> T[N];
int dep[N];
pii low[N];
int in[N];

int edge[M];
int know[M];
vector<int> fq;

void dfs(int u, int pp){
    low[u] = mp(dep[u], -1);
    for(auto x : T[u]){
        if(x.fi == pp) continue;
        if(dep[x.fi] == -1){
            in[x.fi]=x.se;
            dep[x.fi]=dep[u]+1;
            dfs(x.fi, u);
            fq.push_back(x.se);
            low[u] = min(low[u], low[x.fi]);
            if(dep[u] < low[x.fi].fi){
                know[x.se] = 1;
                edge[x.se] = -1; // bridge
            }
            else{
                edge[x.se] = 0; //
            }
        }
        else{
            edge[x.se] = 2; // these f*ck everything up
            low[u] = min(low[u], mp(dep[x.fi], x.se));
        }
    }
}

vector<int> G[M];

int get(int ii, int jj){
    vector<int> aq;
    for(auto x : fq) if(x != ii) aq.push_back(x);
    aq.push_back(jj);
    return count_common_roads(aq);
}

vector<int> cyc;
bool vis[M];
void dfs1(int u){
    vis[u]=true;
    cyc.push_back(u);
    for(auto x : G[u]){
        if(!vis[x]){
            dfs1(x);
        }
    }
}

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
    int m = u.size();
    for(int i = 0 ; i < m ; i ++ ){
        T[u[i]].push_back(mp(v[i], i));
        T[v[i]].push_back(mp(u[i], i));
        edge[i] = -1;
        know[i]=-1;
    }
    for(int i = 0 ; i < n; i ++ ){
        dep[i] = -1;
    }
    dep[0]=0;
    dfs(0,-1);
    for(int i = 0 ; i < m ; i ++) {
        if(dep[u[i]] > dep[v[i]])
            swap(u[i], v[i]);
    }
    for(int i = 1; i < n; i ++ ){
        edge[low[i].se] = 1;
    }
    int faf = count_common_roads(fq);
    int nw;
    int uu, vv;
    int go;
    for(int i = 0 ; i < m ; i ++ ){
        if(edge[i] == 0){
            uu = i;
            vv = low[v[i]].se;
            nw = get(uu, vv);
            if(faf == nw){
                G[uu].push_back(vv);
                G[vv].push_back(uu);
            }
            else{
                if(nw > faf){
                    know[vv]=1;
                    know[uu]=0;
                }
                else{
                    know[vv]=0;
                    know[uu]=1;
                }
            }
        }
        else if(edge[i] == 1){
            vv = i;
            go = v[i];
            while(u[in[go]] != u[i]){
                go = u[in[go]];
            }
            uu = in[go];
            nw = get(uu, vv);
            if(faf == nw){
                G[uu].push_back(vv);
                G[vv].push_back(uu);
            }
            else{
                if(nw > faf){
                    know[vv]=1;
                    know[uu]=0;
                }
                else{
                    know[vv]=0;
                    know[uu]=1;
                }
            }
        }
    }
    int val;
    for(int i = 0 ; i < m ; i ++ ){
        if(edge[i] == 0 || edge[i] == 1){
            if(!vis[i]){
                cyc.clear();
                dfs1(i);
                val = -1;
                for(auto x : cyc){
                    if(know[x] != -1) val = know[x];
                }
                if(val == -1) val = 0;
                for(auto x : cyc) know[x] = val;
            }
        }
    }
    vector<int> soln;
    for(int i = 0 ; i < m ; i ++ ){
        if(edge[i] == 2){
           nw = get(in[v[i]],i);
           know[i]=know[in[v[i]]]+(nw-faf);
        }
        if(know[i] == 1) soln.push_back(i);
    }
	return soln;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3308 KB correct
2 Correct 2 ms 3308 KB correct
3 Correct 2 ms 3308 KB correct
4 Correct 2 ms 3308 KB correct
5 Correct 2 ms 3308 KB correct
6 Correct 2 ms 3308 KB correct
7 Correct 2 ms 3308 KB correct
8 Correct 3 ms 3308 KB correct
9 Correct 2 ms 3308 KB correct
10 Correct 2 ms 3308 KB correct
11 Correct 3 ms 3308 KB correct
12 Correct 2 ms 3308 KB correct
13 Correct 2 ms 3308 KB correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3308 KB correct
2 Correct 2 ms 3308 KB correct
3 Correct 2 ms 3308 KB correct
4 Correct 2 ms 3308 KB correct
5 Correct 2 ms 3308 KB correct
6 Correct 2 ms 3308 KB correct
7 Correct 2 ms 3308 KB correct
8 Correct 3 ms 3308 KB correct
9 Correct 2 ms 3308 KB correct
10 Correct 2 ms 3308 KB correct
11 Correct 3 ms 3308 KB correct
12 Correct 2 ms 3308 KB correct
13 Correct 2 ms 3308 KB correct
14 Correct 4 ms 3308 KB correct
15 Correct 6 ms 3308 KB correct
16 Correct 6 ms 3308 KB correct
17 Correct 4 ms 3308 KB correct
18 Correct 3 ms 3308 KB correct
19 Correct 4 ms 3308 KB correct
20 Correct 4 ms 3308 KB correct
21 Correct 4 ms 3308 KB correct
22 Correct 4 ms 3436 KB correct
23 Correct 3 ms 3308 KB correct
24 Correct 5 ms 3308 KB correct
25 Correct 3 ms 3308 KB correct
26 Correct 3 ms 3308 KB correct
27 Correct 3 ms 3308 KB correct
28 Correct 3 ms 3308 KB correct
29 Correct 3 ms 3308 KB correct
30 Correct 3 ms 3308 KB correct
31 Correct 3 ms 3308 KB correct
32 Correct 3 ms 3308 KB correct
33 Correct 3 ms 3308 KB correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3308 KB correct
2 Correct 2 ms 3308 KB correct
3 Correct 2 ms 3308 KB correct
4 Correct 2 ms 3308 KB correct
5 Correct 2 ms 3308 KB correct
6 Correct 2 ms 3308 KB correct
7 Correct 2 ms 3308 KB correct
8 Correct 3 ms 3308 KB correct
9 Correct 2 ms 3308 KB correct
10 Correct 2 ms 3308 KB correct
11 Correct 3 ms 3308 KB correct
12 Correct 2 ms 3308 KB correct
13 Correct 2 ms 3308 KB correct
14 Correct 4 ms 3308 KB correct
15 Correct 6 ms 3308 KB correct
16 Correct 6 ms 3308 KB correct
17 Correct 4 ms 3308 KB correct
18 Correct 3 ms 3308 KB correct
19 Correct 4 ms 3308 KB correct
20 Correct 4 ms 3308 KB correct
21 Correct 4 ms 3308 KB correct
22 Correct 4 ms 3436 KB correct
23 Correct 3 ms 3308 KB correct
24 Correct 5 ms 3308 KB correct
25 Correct 3 ms 3308 KB correct
26 Correct 3 ms 3308 KB correct
27 Correct 3 ms 3308 KB correct
28 Correct 3 ms 3308 KB correct
29 Correct 3 ms 3308 KB correct
30 Correct 3 ms 3308 KB correct
31 Correct 3 ms 3308 KB correct
32 Correct 3 ms 3308 KB correct
33 Correct 3 ms 3308 KB correct
34 Correct 161 ms 4844 KB correct
35 Correct 155 ms 4716 KB correct
36 Correct 110 ms 4460 KB correct
37 Correct 9 ms 3436 KB correct
38 Correct 158 ms 4844 KB correct
39 Correct 144 ms 4588 KB correct
40 Correct 107 ms 4544 KB correct
41 Correct 161 ms 4716 KB correct
42 Correct 161 ms 4716 KB correct
43 Correct 87 ms 4332 KB correct
44 Correct 70 ms 3948 KB correct
45 Correct 86 ms 4204 KB correct
46 Correct 63 ms 3948 KB correct
47 Correct 28 ms 3564 KB correct
48 Correct 5 ms 3308 KB correct
49 Correct 11 ms 3436 KB correct
50 Correct 28 ms 3564 KB correct
51 Correct 81 ms 4224 KB correct
52 Correct 77 ms 4076 KB correct
53 Correct 63 ms 3948 KB correct
54 Correct 87 ms 4204 KB correct
55 Correct 85 ms 4076 KB correct
56 Correct 91 ms 4100 KB correct
57 Correct 83 ms 4112 KB correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3308 KB correct
2 Correct 3 ms 3308 KB correct
3 Incorrect 133 ms 7404 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3308 KB correct
2 Correct 2 ms 3308 KB correct
3 Correct 2 ms 3308 KB correct
4 Correct 2 ms 3308 KB correct
5 Correct 2 ms 3308 KB correct
6 Correct 2 ms 3308 KB correct
7 Correct 2 ms 3308 KB correct
8 Correct 3 ms 3308 KB correct
9 Correct 2 ms 3308 KB correct
10 Correct 2 ms 3308 KB correct
11 Correct 3 ms 3308 KB correct
12 Correct 2 ms 3308 KB correct
13 Correct 2 ms 3308 KB correct
14 Correct 4 ms 3308 KB correct
15 Correct 6 ms 3308 KB correct
16 Correct 6 ms 3308 KB correct
17 Correct 4 ms 3308 KB correct
18 Correct 3 ms 3308 KB correct
19 Correct 4 ms 3308 KB correct
20 Correct 4 ms 3308 KB correct
21 Correct 4 ms 3308 KB correct
22 Correct 4 ms 3436 KB correct
23 Correct 3 ms 3308 KB correct
24 Correct 5 ms 3308 KB correct
25 Correct 3 ms 3308 KB correct
26 Correct 3 ms 3308 KB correct
27 Correct 3 ms 3308 KB correct
28 Correct 3 ms 3308 KB correct
29 Correct 3 ms 3308 KB correct
30 Correct 3 ms 3308 KB correct
31 Correct 3 ms 3308 KB correct
32 Correct 3 ms 3308 KB correct
33 Correct 3 ms 3308 KB correct
34 Correct 161 ms 4844 KB correct
35 Correct 155 ms 4716 KB correct
36 Correct 110 ms 4460 KB correct
37 Correct 9 ms 3436 KB correct
38 Correct 158 ms 4844 KB correct
39 Correct 144 ms 4588 KB correct
40 Correct 107 ms 4544 KB correct
41 Correct 161 ms 4716 KB correct
42 Correct 161 ms 4716 KB correct
43 Correct 87 ms 4332 KB correct
44 Correct 70 ms 3948 KB correct
45 Correct 86 ms 4204 KB correct
46 Correct 63 ms 3948 KB correct
47 Correct 28 ms 3564 KB correct
48 Correct 5 ms 3308 KB correct
49 Correct 11 ms 3436 KB correct
50 Correct 28 ms 3564 KB correct
51 Correct 81 ms 4224 KB correct
52 Correct 77 ms 4076 KB correct
53 Correct 63 ms 3948 KB correct
54 Correct 87 ms 4204 KB correct
55 Correct 85 ms 4076 KB correct
56 Correct 91 ms 4100 KB correct
57 Correct 83 ms 4112 KB correct
58 Correct 3 ms 3308 KB correct
59 Correct 3 ms 3308 KB correct
60 Incorrect 133 ms 7404 KB WA in grader: NO
61 Halted 0 ms 0 KB -