답안 #1005936

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1005936 2024-06-23T08:19:38 Z SulA One-Way Streets (CEOI17_oneway) C++17
0 / 100
3 ms 4188 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;

vector<int> adj[MAXN+1];
map<pair<int,int>, int> edge;
map<pair<int,int>, char> ans;
int dep[MAXN+1], low[MAXN+1], cntX[MAXN+1], cntY[MAXN+1];

void dfs(int v, int p) {
    dep[v] = low[v] = dep[p] + 1;
    for (int u : adj[v]) {
        if (u == p || u == v) continue;
        if (dep[u] == 0) {
            dfs(u, v);
            low[v] = min(low[v], low[u]);
            cntX[v] += cntX[u];
            cntY[v] += cntY[u];
        } else {
            low[v] = min(low[v], dep[u]);
        }
    }

    if (cntX[v] == cntY[v] || dep[v] != low[v]) return;
    int node1 = v, node2 = p;
    if (edge.find({v, p}) == edge.end()) swap(node1, node2);
    if (edge[{node1, node2}] == 1) { // p-v is a bridge
        pair<int,int> orient;
        if (cntX[v] > cntY[v]) {
            // edge should go from v -> p
            orient = {v, p};
        } else {
            orient = {p, v};
        }

        if (orient == make_pair(node1, node2)) {
            ans[{node1, node2}] = 'R';
        } else {
            ans[{node1, node2}] = 'L';
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n,m; cin >> n >> m;
    pair<int,int> graph[m];
    for (int i = 0; i < m; i++) {
        int a,b; cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
        edge[{a,b}]++;
        graph[i] = {a, b};
    }
    int p; cin >> p;
    while (p--) {
        int x,y; cin >> x >> y;
        cntX[x]++, cntY[y]++;
    }

    for (int v = 1; v <= n; v++) {
        if (dep[v] == 0) {
            dfs(v,0);
        }
    }
    for (auto [a,b] : graph) {
        cout << (ans[{a,b}] == 0 ? 'B' : ans[{a,b}]);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4188 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 2908 KB Output is correct
4 Correct 3 ms 2904 KB Output is correct
5 Correct 2 ms 2908 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 2 ms 2908 KB Output is correct
8 Correct 2 ms 2908 KB Output is correct
9 Incorrect 2 ms 2908 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4188 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 2908 KB Output is correct
4 Correct 3 ms 2904 KB Output is correct
5 Correct 2 ms 2908 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 2 ms 2908 KB Output is correct
8 Correct 2 ms 2908 KB Output is correct
9 Incorrect 2 ms 2908 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4188 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 2908 KB Output is correct
4 Correct 3 ms 2904 KB Output is correct
5 Correct 2 ms 2908 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 2 ms 2908 KB Output is correct
8 Correct 2 ms 2908 KB Output is correct
9 Incorrect 2 ms 2908 KB Output isn't correct
10 Halted 0 ms 0 KB -