답안 #771516

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
771516 2023-07-03T05:43:37 Z peteza One-Way Streets (CEOI17_oneway) C++14
100 / 100
39 ms 12832 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

int n, m, a, b, c;
int v1[100005], v2[100005];
bool vis[100005], visedge[100005];
char ans[100005];
vector<pii> adj[100005];
pii edges[100005];

void dfs(int x, int ass=-1) {
    vis[x] = 1;
    for(auto e:adj[x]) {
        if(visedge[e.second]) continue;
        visedge[e.second] = 1;
        if(vis[e.first]) {
            ans[e.second] = 'B';
            v1[x]++; v1[e.first]--;
        } else {
            dfs(e.first, e.second);
            v1[x] += v1[e.first];
            v2[x] += v2[e.first];
        }
    }
    if(!(~ass)) return;
    if(v1[x]) ans[ass] = 'B';
    else {
        if(!v2[x]) ans[ass] = 'B';
        else {
            ans[ass] = (((edges[ass].first == x) ^ (v2[x] > 0)) ? 'L' : 'R');
        }
    }
}

int main() {
    cin.tie(0) -> sync_with_stdio(0);
    cin >> n >> m;
    for(int i=0;i<m;i++) {
        cin >> a >> b;
        edges[i] = {a, b};
        adj[a].emplace_back(b, i);
        adj[b].emplace_back(a, i);
    }
    cin >> c;
    while(c--) {
        cin >> a >> b;
        v2[a]++; v2[b]--;
    }
    for(int i=1;i<=n;i++) if(!vis[i]) dfs(i);
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2748 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2772 KB Output is correct
6 Correct 1 ms 2772 KB Output is correct
7 Correct 1 ms 2772 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2748 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2772 KB Output is correct
6 Correct 1 ms 2772 KB Output is correct
7 Correct 1 ms 2772 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 23 ms 7872 KB Output is correct
12 Correct 25 ms 8608 KB Output is correct
13 Correct 28 ms 9556 KB Output is correct
14 Correct 29 ms 10220 KB Output is correct
15 Correct 32 ms 10184 KB Output is correct
16 Correct 39 ms 8252 KB Output is correct
17 Correct 25 ms 9816 KB Output is correct
18 Correct 25 ms 8336 KB Output is correct
19 Correct 27 ms 10880 KB Output is correct
20 Correct 24 ms 8252 KB Output is correct
21 Correct 23 ms 7852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2748 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2772 KB Output is correct
6 Correct 1 ms 2772 KB Output is correct
7 Correct 1 ms 2772 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 23 ms 7872 KB Output is correct
12 Correct 25 ms 8608 KB Output is correct
13 Correct 28 ms 9556 KB Output is correct
14 Correct 29 ms 10220 KB Output is correct
15 Correct 32 ms 10184 KB Output is correct
16 Correct 39 ms 8252 KB Output is correct
17 Correct 25 ms 9816 KB Output is correct
18 Correct 25 ms 8336 KB Output is correct
19 Correct 27 ms 10880 KB Output is correct
20 Correct 24 ms 8252 KB Output is correct
21 Correct 23 ms 7852 KB Output is correct
22 Correct 37 ms 9752 KB Output is correct
23 Correct 37 ms 8228 KB Output is correct
24 Correct 39 ms 8324 KB Output is correct
25 Correct 39 ms 12832 KB Output is correct
26 Correct 38 ms 9428 KB Output is correct
27 Correct 36 ms 8332 KB Output is correct
28 Correct 21 ms 5836 KB Output is correct
29 Correct 36 ms 7828 KB Output is correct
30 Correct 36 ms 7904 KB Output is correct
31 Correct 36 ms 8268 KB Output is correct
32 Correct 34 ms 10096 KB Output is correct