답안 #114694

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
114694 2019-06-02T10:58:18 Z PeppaPig One-Way Streets (CEOI17_oneway) C++14
100 / 100
155 ms 16584 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int dsu[N];

int find(int x) { return dsu[x] = x == dsu[x] ? x : find(dsu[x]); }

int n, m, p;
int a[N], b[N];
vector<int> g[N];

int pre[N], low[N];
bitset<N> br;

void tarjan(int u, int p) {
    static int idx = 0;
    pre[u] = low[u] = ++idx;
    for(int i : g[u]) if(i != p) {
        int v = a[i] ^ b[i] ^ u;
        if(!pre[v]) {
            tarjan(v, i);
            low[u] = min(low[u], low[v]);
            if(low[v] > pre[u]) br[i] = true;
        } else low[u] = min(low[u], pre[v]);
    }
}

int dp[N], dep[N];

void dfs(int u, int p) {
    for(int i : g[u]) if(i != p) {
        int v = find(a[i]) ^ find(b[i]) ^ u;
        dep[v] = dep[u] + 1;
        dfs(v, i);
        dp[u] += dp[v];
    }
}

int main() {
    iota(dsu, dsu+N, 0);

    scanf("%d %d", &n, &m);
    for(int i = 1; i <= m; i++) {
        scanf("%d %d", a+i, b+i);
        g[a[i]].emplace_back(i);
        g[b[i]].emplace_back(i);
    }

    for(int i = 1; i <= n; i++) if(!pre[i]) tarjan(i, 0); 
    for(int i = 1; i <= m; i++) if(!br[i]) dsu[find(a[i])] = find(b[i]);
    for(int i = 1; i <= n; i++) g[i].clear();
    for(int i = 1; i <= m; i++) if(br[i]) {
        g[find(a[i])].emplace_back(i);
        g[find(b[i])].emplace_back(i);
    }
    
    scanf("%d", &p);
    for(int i = 1, x, y; i <= p; i++) {
        scanf("%d %d", &x, &y);
        ++dp[find(x)], --dp[find(y)];
    }
    for(int i = 1; i <= n; i++) if(!dep[find(i)]) {
        dep[find(i)] = 1;
        dfs(find(i), 0);
    }
    for(int i = 1; i <= m; i++) {
        if(!br[i]) printf("B");
        else {
            int u = dep[find(a[i])] > dep[find(b[i])] ? a[i] : b[i];
            if(dp[find(u)] == 0) printf("B");
            else if((dp[find(u)] > 0) == (u == a[i])) printf("R");
            else printf("L");
        } 
    }
    printf("\n");

    return 0;
}

Compilation message

oneway.cpp: In function 'int main()':
oneway.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", a+i, b+i);
         ~~~~~^~~~~~~~~~~~~~~~~~~
oneway.cpp:60:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &p);
     ~~~~~^~~~~~~~~~
oneway.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3072 KB Output is correct
2 Correct 4 ms 3072 KB Output is correct
3 Correct 4 ms 3200 KB Output is correct
4 Correct 5 ms 3200 KB Output is correct
5 Correct 4 ms 3200 KB Output is correct
6 Correct 5 ms 3328 KB Output is correct
7 Correct 5 ms 3200 KB Output is correct
8 Correct 5 ms 3200 KB Output is correct
9 Correct 4 ms 3072 KB Output is correct
10 Correct 5 ms 3200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3072 KB Output is correct
2 Correct 4 ms 3072 KB Output is correct
3 Correct 4 ms 3200 KB Output is correct
4 Correct 5 ms 3200 KB Output is correct
5 Correct 4 ms 3200 KB Output is correct
6 Correct 5 ms 3328 KB Output is correct
7 Correct 5 ms 3200 KB Output is correct
8 Correct 5 ms 3200 KB Output is correct
9 Correct 4 ms 3072 KB Output is correct
10 Correct 5 ms 3200 KB Output is correct
11 Correct 58 ms 8336 KB Output is correct
12 Correct 71 ms 9356 KB Output is correct
13 Correct 82 ms 10872 KB Output is correct
14 Correct 110 ms 11740 KB Output is correct
15 Correct 120 ms 12024 KB Output is correct
16 Correct 110 ms 10104 KB Output is correct
17 Correct 122 ms 11852 KB Output is correct
18 Correct 135 ms 9900 KB Output is correct
19 Correct 117 ms 13304 KB Output is correct
20 Correct 72 ms 9080 KB Output is correct
21 Correct 61 ms 9080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3072 KB Output is correct
2 Correct 4 ms 3072 KB Output is correct
3 Correct 4 ms 3200 KB Output is correct
4 Correct 5 ms 3200 KB Output is correct
5 Correct 4 ms 3200 KB Output is correct
6 Correct 5 ms 3328 KB Output is correct
7 Correct 5 ms 3200 KB Output is correct
8 Correct 5 ms 3200 KB Output is correct
9 Correct 4 ms 3072 KB Output is correct
10 Correct 5 ms 3200 KB Output is correct
11 Correct 58 ms 8336 KB Output is correct
12 Correct 71 ms 9356 KB Output is correct
13 Correct 82 ms 10872 KB Output is correct
14 Correct 110 ms 11740 KB Output is correct
15 Correct 120 ms 12024 KB Output is correct
16 Correct 110 ms 10104 KB Output is correct
17 Correct 122 ms 11852 KB Output is correct
18 Correct 135 ms 9900 KB Output is correct
19 Correct 117 ms 13304 KB Output is correct
20 Correct 72 ms 9080 KB Output is correct
21 Correct 61 ms 9080 KB Output is correct
22 Correct 144 ms 13076 KB Output is correct
23 Correct 149 ms 11020 KB Output is correct
24 Correct 153 ms 11120 KB Output is correct
25 Correct 140 ms 16584 KB Output is correct
26 Correct 155 ms 12536 KB Output is correct
27 Correct 136 ms 11356 KB Output is correct
28 Correct 42 ms 6136 KB Output is correct
29 Correct 88 ms 9720 KB Output is correct
30 Correct 85 ms 10104 KB Output is correct
31 Correct 87 ms 10204 KB Output is correct
32 Correct 99 ms 12892 KB Output is correct