답안 #585363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
585363 2022-06-28T17:49:55 Z Jomnoi One-Way Streets (CEOI17_oneway) C++17
100 / 100
87 ms 12940 KB
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 1e5 + 5;
const int MAX_M = 1e5 + 5;

vector <int> graph[MAX_N];
int L[MAX_M], R[MAX_M];
bool visited[MAX_N];
bool treeEdge[MAX_M];
int qs1[MAX_N], qs2[MAX_N];
char ans[MAX_M];

void dfs(int u, int p) {
    visited[u] = true;
    for(auto i : graph[u]) {
        int v = u ^ L[i] ^ R[i];
        if(v == p) {
            continue;
        }

        if(visited[v] == false) {
            treeEdge[i] = true;
            dfs(v, u);
        }
        else {
            if(L[i] == u) {
                swap(L[i], R[i]);
            }
        }
    }
}

void dfs2(int u, int p) {
    visited[u] = false;
    for(auto i : graph[u]) {
        int v = u ^ L[i] ^ R[i];
        if(v == p or visited[v] == false) {
            continue;
        }

        dfs2(v, u);

        qs1[u] += qs1[v];
        qs2[u] += qs2[v];
        if(qs1[v] != 0 or qs2[v] == 0) {
            ans[i] = 'B';
            continue;
        }

        if(qs2[v] > 0) {
            if(v == L[i]) {
                ans[i] = 'R';
            }
            else {
                ans[i] = 'L';
            }
        }
        else {
            if(u == L[i]) {
                ans[i] = 'R';
            }
            else {
                ans[i] = 'L';
            }
        }
    }
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int n, m;
    cin >> n >> m;

    for(int i = 1; i <= m; i++) {
        cin >> L[i] >> R[i];

        graph[L[i]].push_back(i);
        graph[R[i]].push_back(i);
    }

    for(int i = 1; i <= n; i++) {
        if(visited[i] == false) {
            dfs(i, -1);
        }
    }

    for(int i = 1; i <= m; i++) {
        if(treeEdge[i] == false) {
            ans[i] = 'B';
            qs1[L[i]]++;
            qs1[R[i]]--;
        }
    }

    int p;
    cin >> p;
    
    while(p--) {
        int x, y;
        cin >> x >> y;

        qs2[x]++;
        qs2[y]--;
    }

    for(int i = 1; i <= n; i++) {
        if(visited[i] == true) {
            dfs2(i, -1);
        }
    }

    for(int i = 1; i <= m; i++) {
        cout << ans[i];
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2676 KB Output is correct
3 Correct 2 ms 2676 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2680 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
7 Correct 3 ms 2772 KB Output is correct
8 Correct 2 ms 2684 KB Output is correct
9 Correct 3 ms 2644 KB Output is correct
10 Correct 2 ms 2624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2676 KB Output is correct
3 Correct 2 ms 2676 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2680 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
7 Correct 3 ms 2772 KB Output is correct
8 Correct 2 ms 2684 KB Output is correct
9 Correct 3 ms 2644 KB Output is correct
10 Correct 2 ms 2624 KB Output is correct
11 Correct 53 ms 7144 KB Output is correct
12 Correct 52 ms 8060 KB Output is correct
13 Correct 55 ms 9084 KB Output is correct
14 Correct 56 ms 9712 KB Output is correct
15 Correct 87 ms 9804 KB Output is correct
16 Correct 70 ms 8276 KB Output is correct
17 Correct 58 ms 9876 KB Output is correct
18 Correct 67 ms 8260 KB Output is correct
19 Correct 51 ms 11080 KB Output is correct
20 Correct 62 ms 7832 KB Output is correct
21 Correct 45 ms 7604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2676 KB Output is correct
3 Correct 2 ms 2676 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2680 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
7 Correct 3 ms 2772 KB Output is correct
8 Correct 2 ms 2684 KB Output is correct
9 Correct 3 ms 2644 KB Output is correct
10 Correct 2 ms 2624 KB Output is correct
11 Correct 53 ms 7144 KB Output is correct
12 Correct 52 ms 8060 KB Output is correct
13 Correct 55 ms 9084 KB Output is correct
14 Correct 56 ms 9712 KB Output is correct
15 Correct 87 ms 9804 KB Output is correct
16 Correct 70 ms 8276 KB Output is correct
17 Correct 58 ms 9876 KB Output is correct
18 Correct 67 ms 8260 KB Output is correct
19 Correct 51 ms 11080 KB Output is correct
20 Correct 62 ms 7832 KB Output is correct
21 Correct 45 ms 7604 KB Output is correct
22 Correct 78 ms 9960 KB Output is correct
23 Correct 80 ms 8352 KB Output is correct
24 Correct 82 ms 8360 KB Output is correct
25 Correct 68 ms 12940 KB Output is correct
26 Correct 81 ms 9472 KB Output is correct
27 Correct 75 ms 8392 KB Output is correct
28 Correct 30 ms 5300 KB Output is correct
29 Correct 67 ms 7480 KB Output is correct
30 Correct 65 ms 7588 KB Output is correct
31 Correct 63 ms 7840 KB Output is correct
32 Correct 60 ms 9836 KB Output is correct