답안 #720398

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
720398 2023-04-08T06:39:52 Z Jarif_Rahman Simurgh (IOI17_simurgh) C++17
51 / 100
125 ms 4684 KB
#include "simurgh.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

int n, m;
vector<vector<pair<int, int>>> graph, tree, backedge;
vector<bool> bl;
vector<bool> royal;
vector<int> depth;
vector<int> cur;
vector<pair<int, int>> DD;
int X;

void dfs0(int nd, int d = 0, int pi = -1){
    bl[nd] = 1;
    depth[nd] = d;
    for(auto [x, i]: graph[nd]) if(i != pi) {
        if(bl[x]){
            if(depth[x] < depth[nd]) backedge[nd].pb({x, i});
        }
        else{
            bl[x] = 1;
            tree[nd].pb({x, i});
            cur.pb(i);
            dfs0(x, d+1, i);
        }
    }
}


int ND;
pair<int, int> D;
void dfs_find(int nd, int ss = -1){
    if(DD[nd].f != -1 && depth[DD[nd].f] < depth[D.f]) D = DD[nd];
    if(depth[nd] < depth[ND]) return;
    for(auto [x, i]: graph[nd]) if(royal[i] && x != ss) dfs_find(x, nd);
}

void dfs(int nd, int i){
    for(auto [x, j]: tree[nd]) dfs(x, j);
    if(i == -1) return;
    ND = nd;
    D = {nd, i};
    dfs_find(nd);

    auto it = find(cur.begin(), cur.end(), i);
    if(depth[nd] <= depth[D.f]){
        vector<int> ge, eq = {i};
        pair<int, int> eq_mn = D, ge_mn = D;
        for(auto [x, j]: backedge[nd]){
            *it = j;
            int c = count_common_roads(cur);
            if(c == X){
                eq.pb(j);
                if(depth[x] < depth[eq_mn.f]) eq_mn = {x, j};
            }
            else if(c > X){
                ge.pb(j);
                if(depth[x] < depth[ge_mn.f]) ge_mn = {x, j};
            }
        }
        *it = i;
        if(ge.empty()) for(int j: eq) royal[j] = 1;
        else for(int j: ge) royal[j] = 1;
        if(ge.empty()) DD[nd] = eq_mn;
        else DD[nd] = ge_mn;
    }
    else{
        *it = D.sc;
        int Y = count_common_roads(cur);
        for(auto [x, j]: backedge[nd]){
            *it = j;
            int c = count_common_roads(cur);
            if(c == Y){
                royal[j] = 1;
                if(depth[x] < depth[D.f]) D = {x, j};
            }
        }
        *it = i;
        if(X == Y) royal[i] = 1;
        DD[nd] = D;
    }
}

vector<int> find_roads(int _n, vector<int> U, vector<int> V){
    swap(n, _n);
    m = U.size();
    graph.resize(n);
    tree.resize(n);
    backedge.resize(n);
    bl.assign(n, 0);
    depth.resize(n);
    royal.assign(m, 0);
    DD.resize(n, {-1, -1});

    for(int i = 0; i < m; i++){
        graph[U[i]].pb({V[i], i});
        graph[V[i]].pb({U[i], i});
    }
    dfs0(0);
    X = count_common_roads(cur);
    dfs(0, -1);
    vector<int> ans;
    for(int i = 0; i < m; i++) if(royal[i]) ans.pb(i);
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB correct
2 Correct 1 ms 296 KB correct
3 Correct 1 ms 300 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 1 ms 300 KB correct
6 Correct 1 ms 212 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 212 KB correct
9 Correct 1 ms 304 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 1 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 1 ms 212 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB correct
2 Correct 1 ms 296 KB correct
3 Correct 1 ms 300 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 1 ms 300 KB correct
6 Correct 1 ms 212 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 212 KB correct
9 Correct 1 ms 304 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 1 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 1 ms 212 KB correct
14 Correct 2 ms 340 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 512 KB correct
17 Correct 2 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 2 ms 304 KB correct
20 Correct 2 ms 340 KB correct
21 Correct 1 ms 340 KB correct
22 Correct 1 ms 340 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 212 KB correct
26 Correct 1 ms 340 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 212 KB correct
29 Correct 1 ms 300 KB correct
30 Correct 2 ms 340 KB correct
31 Correct 1 ms 340 KB correct
32 Correct 1 ms 296 KB correct
33 Correct 1 ms 340 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB correct
2 Correct 1 ms 296 KB correct
3 Correct 1 ms 300 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 1 ms 300 KB correct
6 Correct 1 ms 212 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 212 KB correct
9 Correct 1 ms 304 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 1 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 1 ms 212 KB correct
14 Correct 2 ms 340 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 512 KB correct
17 Correct 2 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 2 ms 304 KB correct
20 Correct 2 ms 340 KB correct
21 Correct 1 ms 340 KB correct
22 Correct 1 ms 340 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 212 KB correct
26 Correct 1 ms 340 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 212 KB correct
29 Correct 1 ms 300 KB correct
30 Correct 2 ms 340 KB correct
31 Correct 1 ms 340 KB correct
32 Correct 1 ms 296 KB correct
33 Correct 1 ms 340 KB correct
34 Correct 113 ms 1716 KB correct
35 Correct 112 ms 1780 KB correct
36 Correct 76 ms 1492 KB correct
37 Correct 5 ms 340 KB correct
38 Correct 116 ms 1808 KB correct
39 Correct 96 ms 1684 KB correct
40 Correct 76 ms 1492 KB correct
41 Correct 125 ms 1808 KB correct
42 Correct 123 ms 1836 KB correct
43 Correct 61 ms 1268 KB correct
44 Correct 50 ms 988 KB correct
45 Correct 59 ms 1068 KB correct
46 Correct 44 ms 980 KB correct
47 Correct 21 ms 620 KB correct
48 Correct 2 ms 340 KB correct
49 Correct 7 ms 340 KB correct
50 Correct 20 ms 644 KB correct
51 Correct 58 ms 980 KB correct
52 Correct 48 ms 988 KB correct
53 Correct 43 ms 852 KB correct
54 Correct 61 ms 1256 KB correct
55 Correct 59 ms 1088 KB correct
56 Correct 58 ms 1088 KB correct
57 Correct 57 ms 1108 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB correct
2 Correct 1 ms 212 KB correct
3 Incorrect 100 ms 4684 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB correct
2 Correct 1 ms 296 KB correct
3 Correct 1 ms 300 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 1 ms 300 KB correct
6 Correct 1 ms 212 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 212 KB correct
9 Correct 1 ms 304 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 1 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 1 ms 212 KB correct
14 Correct 2 ms 340 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 512 KB correct
17 Correct 2 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 2 ms 304 KB correct
20 Correct 2 ms 340 KB correct
21 Correct 1 ms 340 KB correct
22 Correct 1 ms 340 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 212 KB correct
26 Correct 1 ms 340 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 212 KB correct
29 Correct 1 ms 300 KB correct
30 Correct 2 ms 340 KB correct
31 Correct 1 ms 340 KB correct
32 Correct 1 ms 296 KB correct
33 Correct 1 ms 340 KB correct
34 Correct 113 ms 1716 KB correct
35 Correct 112 ms 1780 KB correct
36 Correct 76 ms 1492 KB correct
37 Correct 5 ms 340 KB correct
38 Correct 116 ms 1808 KB correct
39 Correct 96 ms 1684 KB correct
40 Correct 76 ms 1492 KB correct
41 Correct 125 ms 1808 KB correct
42 Correct 123 ms 1836 KB correct
43 Correct 61 ms 1268 KB correct
44 Correct 50 ms 988 KB correct
45 Correct 59 ms 1068 KB correct
46 Correct 44 ms 980 KB correct
47 Correct 21 ms 620 KB correct
48 Correct 2 ms 340 KB correct
49 Correct 7 ms 340 KB correct
50 Correct 20 ms 644 KB correct
51 Correct 58 ms 980 KB correct
52 Correct 48 ms 988 KB correct
53 Correct 43 ms 852 KB correct
54 Correct 61 ms 1256 KB correct
55 Correct 59 ms 1088 KB correct
56 Correct 58 ms 1088 KB correct
57 Correct 57 ms 1108 KB correct
58 Correct 0 ms 340 KB correct
59 Correct 1 ms 212 KB correct
60 Incorrect 100 ms 4684 KB WA in grader: NO
61 Halted 0 ms 0 KB -