답안 #77023

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
77023 2018-09-20T05:40:48 Z win11905 One-Way Streets (CEOI17_oneway) C++11
100 / 100
123 ms 13036 KB
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;

const int N = 1e5+5;

int n, m, p, d1[N], d2[N];
char Answer[N];
bitset<N> check, checkE;
pii E[N];
vector<pii> g[N];

void dfs(int u, int p) {
    check[u] = true;
    for(pii v : g[u]) if(v.x != p) {
        if(check[v.x]) { if(E[v.y].x == u) swap(E[v.y].x, E[v.y].y); }
        else checkE[v.y] = true, dfs(v.x, u);
    }
}

void solve(int u, int p) {
    check[u] = false;
    for(pii v : g[u]) if(v.x != p and check[v.x]) {
        solve(v.x, u);
        Answer[v.y] = 'B';
        d1[u] += d1[v.x], d2[u] += d2[v.x];
        if(d1[v.x] || !d2[v.x]) continue;
        Answer[v.y] = (d2[v.x] > 0 ? v.x : u) == E[v.y].x ? 'R' : 'L'; 
    } 
}

int main() {
    scanf("%d %d", &n, &m);
    for(int i = 0, u, v; i < m; ++i) {
        scanf("%d %d", &u, &v);
        g[u].emplace_back(v, i), g[v].emplace_back(u, i);
        E[i] = pii(u, v);
    }
    for(int i = 1; i <= n; ++i) if(!check[i]) dfs(i, 0);
    for(int i = 0; i < m; ++i) if(!checkE[i]) Answer[i] = 'B', d1[E[i].x]++, d1[E[i].y]--;
    scanf("%d", &p);
    for(int i = 0, a, b; i < p; ++i) {
        scanf("%d %d", &a, &b);
        d2[a]++, d2[b]--;
    }
    for(int i = 1; i <= n; ++i) if(check[i]) solve(i, 0);
    printf("%s", Answer);
}

Compilation message

oneway.cpp: In function 'int main()':
oneway.cpp:35: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:37:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &p);
     ~~~~~^~~~~~~~~~
oneway.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2812 KB Output is correct
3 Correct 5 ms 3036 KB Output is correct
4 Correct 5 ms 3036 KB Output is correct
5 Correct 4 ms 3036 KB Output is correct
6 Correct 5 ms 3036 KB Output is correct
7 Correct 4 ms 3096 KB Output is correct
8 Correct 5 ms 3096 KB Output is correct
9 Correct 5 ms 3096 KB Output is correct
10 Correct 4 ms 3096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2812 KB Output is correct
3 Correct 5 ms 3036 KB Output is correct
4 Correct 5 ms 3036 KB Output is correct
5 Correct 4 ms 3036 KB Output is correct
6 Correct 5 ms 3036 KB Output is correct
7 Correct 4 ms 3096 KB Output is correct
8 Correct 5 ms 3096 KB Output is correct
9 Correct 5 ms 3096 KB Output is correct
10 Correct 4 ms 3096 KB Output is correct
11 Correct 61 ms 7864 KB Output is correct
12 Correct 71 ms 8828 KB Output is correct
13 Correct 80 ms 9732 KB Output is correct
14 Correct 93 ms 10340 KB Output is correct
15 Correct 113 ms 10396 KB Output is correct
16 Correct 83 ms 10396 KB Output is correct
17 Correct 73 ms 10396 KB Output is correct
18 Correct 79 ms 10396 KB Output is correct
19 Correct 75 ms 11180 KB Output is correct
20 Correct 78 ms 11180 KB Output is correct
21 Correct 62 ms 11180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2812 KB Output is correct
3 Correct 5 ms 3036 KB Output is correct
4 Correct 5 ms 3036 KB Output is correct
5 Correct 4 ms 3036 KB Output is correct
6 Correct 5 ms 3036 KB Output is correct
7 Correct 4 ms 3096 KB Output is correct
8 Correct 5 ms 3096 KB Output is correct
9 Correct 5 ms 3096 KB Output is correct
10 Correct 4 ms 3096 KB Output is correct
11 Correct 61 ms 7864 KB Output is correct
12 Correct 71 ms 8828 KB Output is correct
13 Correct 80 ms 9732 KB Output is correct
14 Correct 93 ms 10340 KB Output is correct
15 Correct 113 ms 10396 KB Output is correct
16 Correct 83 ms 10396 KB Output is correct
17 Correct 73 ms 10396 KB Output is correct
18 Correct 79 ms 10396 KB Output is correct
19 Correct 75 ms 11180 KB Output is correct
20 Correct 78 ms 11180 KB Output is correct
21 Correct 62 ms 11180 KB Output is correct
22 Correct 106 ms 11180 KB Output is correct
23 Correct 109 ms 11180 KB Output is correct
24 Correct 105 ms 11180 KB Output is correct
25 Correct 114 ms 13036 KB Output is correct
26 Correct 102 ms 13036 KB Output is correct
27 Correct 105 ms 13036 KB Output is correct
28 Correct 52 ms 13036 KB Output is correct
29 Correct 100 ms 13036 KB Output is correct
30 Correct 92 ms 13036 KB Output is correct
31 Correct 123 ms 13036 KB Output is correct
32 Correct 95 ms 13036 KB Output is correct