# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
63155 | 2018-08-01T01:27:33 Z | khsoo01 | One-Way Streets (CEOI17_oneway) | C++11 | 219 ms | 44988 KB |
#include<bits/stdc++.h> #define X first #define Y second using namespace std; typedef pair<int,int> pii; const int N = 100005; int n, m, q, ans[N], dep[N], p[N], dir[N]; bool vis[N], bc[N]; vector<int> adj[N]; vector<pii> edg; struct disj { int par[N]; void init () {iota(par, par+n+1, 0);} int Find (int X) { if(par[X] == X) return X; return par[X] = Find(par[X]); } void Union (int A, int B) { A = Find(A); B = Find(B); if(A == B) return; par[A] = B; } } uf; void calc (int C, int P) { if(vis[C]) return; vis[C] = true; dep[C] = dep[P] + 1; p[C] = P; for(auto &T : adj[C]) calc(T, C); } int main() { scanf("%d%d",&n,&m); for(int i=0;i<m;i++) { int A, B; scanf("%d%d",&A,&B); edg.push_back({A, B}); adj[A].push_back(B); adj[B].push_back(A); } for(int i=1;i<=n;i++) { if(!vis[i]) calc(i, 0); } uf.init(); scanf("%d",&q); for(int i=1;i<=q;i++) { int A, B; scanf("%d%d",&A,&B); while(uf.Find(A) != uf.Find(B)) { A = uf.Find(A); B = uf.Find(B); if(dep[A] > dep[B]) { dir[A] = 1; uf.Union(A, p[A]); } else { dir[B] = 2; uf.Union(B, p[B]); } } } uf.init(); fill(vis+1, vis+1+n, false); for(int i=1;i<=n;i++) { bool flag = false; for(auto &T : adj[i]) { if(!flag && T == p[i]) { flag = true; continue; } while(dep[uf.Find(i)] > dep[T]) { int I = uf.Find(i); bc[I] = true; uf.Union(I, p[I]); } } } for(int i=0;i<m;i++) { if(p[edg[i].X] == edg[i].Y) { int I = edg[i].X; if(bc[I] || !dir[I]) printf("B"); else if(dir[I] == 1) printf("R"); else printf("L"); } else if(p[edg[i].Y] == edg[i].X) { int I = edg[i].Y; if(bc[I] || !dir[I]) printf("B"); else if(dir[I] == 1) printf("L"); else printf("R"); } else printf("B"); } puts(""); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2680 KB | Output is correct |
2 | Correct | 5 ms | 2688 KB | Output is correct |
3 | Correct | 6 ms | 2852 KB | Output is correct |
4 | Correct | 6 ms | 2912 KB | Output is correct |
5 | Correct | 7 ms | 3040 KB | Output is correct |
6 | Correct | 6 ms | 3100 KB | Output is correct |
7 | Correct | 6 ms | 3168 KB | Output is correct |
8 | Correct | 5 ms | 3256 KB | Output is correct |
9 | Correct | 6 ms | 3256 KB | Output is correct |
10 | Correct | 7 ms | 3256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2680 KB | Output is correct |
2 | Correct | 5 ms | 2688 KB | Output is correct |
3 | Correct | 6 ms | 2852 KB | Output is correct |
4 | Correct | 6 ms | 2912 KB | Output is correct |
5 | Correct | 7 ms | 3040 KB | Output is correct |
6 | Correct | 6 ms | 3100 KB | Output is correct |
7 | Correct | 6 ms | 3168 KB | Output is correct |
8 | Correct | 5 ms | 3256 KB | Output is correct |
9 | Correct | 6 ms | 3256 KB | Output is correct |
10 | Correct | 7 ms | 3256 KB | Output is correct |
11 | Correct | 60 ms | 7500 KB | Output is correct |
12 | Correct | 103 ms | 9196 KB | Output is correct |
13 | Correct | 108 ms | 11268 KB | Output is correct |
14 | Correct | 141 ms | 13304 KB | Output is correct |
15 | Correct | 130 ms | 14768 KB | Output is correct |
16 | Correct | 124 ms | 15468 KB | Output is correct |
17 | Correct | 140 ms | 17464 KB | Output is correct |
18 | Correct | 115 ms | 18072 KB | Output is correct |
19 | Correct | 90 ms | 20248 KB | Output is correct |
20 | Correct | 101 ms | 20248 KB | Output is correct |
21 | Correct | 72 ms | 20248 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2680 KB | Output is correct |
2 | Correct | 5 ms | 2688 KB | Output is correct |
3 | Correct | 6 ms | 2852 KB | Output is correct |
4 | Correct | 6 ms | 2912 KB | Output is correct |
5 | Correct | 7 ms | 3040 KB | Output is correct |
6 | Correct | 6 ms | 3100 KB | Output is correct |
7 | Correct | 6 ms | 3168 KB | Output is correct |
8 | Correct | 5 ms | 3256 KB | Output is correct |
9 | Correct | 6 ms | 3256 KB | Output is correct |
10 | Correct | 7 ms | 3256 KB | Output is correct |
11 | Correct | 60 ms | 7500 KB | Output is correct |
12 | Correct | 103 ms | 9196 KB | Output is correct |
13 | Correct | 108 ms | 11268 KB | Output is correct |
14 | Correct | 141 ms | 13304 KB | Output is correct |
15 | Correct | 130 ms | 14768 KB | Output is correct |
16 | Correct | 124 ms | 15468 KB | Output is correct |
17 | Correct | 140 ms | 17464 KB | Output is correct |
18 | Correct | 115 ms | 18072 KB | Output is correct |
19 | Correct | 90 ms | 20248 KB | Output is correct |
20 | Correct | 101 ms | 20248 KB | Output is correct |
21 | Correct | 72 ms | 20248 KB | Output is correct |
22 | Correct | 161 ms | 24344 KB | Output is correct |
23 | Correct | 131 ms | 26004 KB | Output is correct |
24 | Correct | 219 ms | 28324 KB | Output is correct |
25 | Correct | 163 ms | 32420 KB | Output is correct |
26 | Correct | 165 ms | 33404 KB | Output is correct |
27 | Correct | 151 ms | 35240 KB | Output is correct |
28 | Correct | 60 ms | 35240 KB | Output is correct |
29 | Correct | 163 ms | 36952 KB | Output is correct |
30 | Correct | 119 ms | 39212 KB | Output is correct |
31 | Correct | 114 ms | 41600 KB | Output is correct |
32 | Correct | 185 ms | 44988 KB | Output is correct |