# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
303943 | 2020-09-20T19:59:18 Z | peuch | One-Way Streets (CEOI17_oneway) | C++17 | 229 ms | 33272 KB |
#include<bits/stdc++.h> using namespace std; const int MAXN = 100010; int n, m, p; int low[MAXN], pre[MAXN]; int cnt; int bridge[MAXN]; pair<int, int> edge[MAXN]; int rep[MAXN], tam[MAXN]; int auxSum[MAXN]; int marc[MAXN]; int ans[MAXN]; vector<int> ar[MAXN], id[MAXN]; vector<int> tree[MAXN], treeID[MAXN]; void dfs(int cur, int pai); void uni(int a, int b); int find(int a); void endCalc(int cur, int pai); int main(){ scanf("%d %d", &n, &m); for(int i = 1; i <= n; i++) rep[i] = i, tam[i] = 1; for(int i = 1; i <= m; i++){ int a, b; scanf("%d %d", &a, &b); ar[a].push_back(b); ar[b].push_back(a); id[a].push_back(i); id[b].push_back(i); edge[i] = make_pair(a, b); } for(int i = 1; i <= n; i++) if(marc[i] != 1) dfs(i, 0); for(int i = 1; i <= m; i++){ if(bridge[i]) continue; uni(edge[i].first, edge[i].second); } for(int i = 1; i <= m; i++){ if(!bridge[i]) continue; int a = edge[i].first; int b = edge[i].second; a = find(a); b = find(b); tree[a].push_back(b); tree[b].push_back(a); treeID[a].push_back(i); treeID[b].push_back(i); } scanf("%d", &p); for(int i = 1; i <= p; i++){ int a, b; scanf("%d %d", &a, &b); a = find(a); b = find(b); auxSum[a]++; auxSum[b]--; } for(int i = 1; i <= n; i++) if(marc[find(i)] != 2) endCalc(find(i), 0); for(int i = 1; i <= m; i++){ if(ans[i] == 1) printf("R"); else if(ans[i] == -1) printf("L"); else printf("B"); } printf("\n"); return 0; } void dfs(int cur, int pai){ marc[cur] = 1; pre[cur] = low[cur] = ++cnt; for(int i = 0; i < ar[cur].size(); i++){ int viz = ar[cur][i]; if(id[cur][i] == pai) continue; if(pre[viz] != 0) low[cur] = min(low[cur], pre[viz]); else{ dfs(viz, id[cur][i]); if(low[viz] > pre[cur]) bridge[id[cur][i]] = 1; low[cur] = min(low[cur], low[viz]); } } } void uni(int a, int b){ a = find(a); b = find(b); if(a == b) return; if(tam[a] > tam[b]) tam[a] += tam[b], rep[b] = a; else tam[b] += tam[a], rep[a] = b; } int find(int a){ if(rep[a] == a) return a; return rep[a] = find(rep[a]); } void endCalc(int cur, int pai){ marc[cur] = 2; for(int i = 0; i < tree[cur].size(); i++){ int viz = tree[cur][i]; int eID = treeID[cur][i]; if(viz == pai) continue; endCalc(viz, cur); if(auxSum[viz] < 0){ if(find(edge[eID].first) == cur) ans[eID] = 1; else ans[eID] = -1; } else if(auxSum[viz] > 0){ if(find(edge[eID].first) == cur) ans[eID] = -1; else ans[eID] = 1; } auxSum[cur] += auxSum[viz]; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9728 KB | Output is correct |
2 | Correct | 6 ms | 9728 KB | Output is correct |
3 | Correct | 7 ms | 9856 KB | Output is correct |
4 | Correct | 7 ms | 9856 KB | Output is correct |
5 | Correct | 7 ms | 9984 KB | Output is correct |
6 | Correct | 7 ms | 9856 KB | Output is correct |
7 | Correct | 7 ms | 9984 KB | Output is correct |
8 | Correct | 7 ms | 9984 KB | Output is correct |
9 | Correct | 7 ms | 9856 KB | Output is correct |
10 | Correct | 7 ms | 9856 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9728 KB | Output is correct |
2 | Correct | 6 ms | 9728 KB | Output is correct |
3 | Correct | 7 ms | 9856 KB | Output is correct |
4 | Correct | 7 ms | 9856 KB | Output is correct |
5 | Correct | 7 ms | 9984 KB | Output is correct |
6 | Correct | 7 ms | 9856 KB | Output is correct |
7 | Correct | 7 ms | 9984 KB | Output is correct |
8 | Correct | 7 ms | 9984 KB | Output is correct |
9 | Correct | 7 ms | 9856 KB | Output is correct |
10 | Correct | 7 ms | 9856 KB | Output is correct |
11 | Correct | 75 ms | 16376 KB | Output is correct |
12 | Correct | 89 ms | 18040 KB | Output is correct |
13 | Correct | 103 ms | 19960 KB | Output is correct |
14 | Correct | 127 ms | 22904 KB | Output is correct |
15 | Correct | 145 ms | 24184 KB | Output is correct |
16 | Correct | 214 ms | 27512 KB | Output is correct |
17 | Correct | 147 ms | 29176 KB | Output is correct |
18 | Correct | 184 ms | 27896 KB | Output is correct |
19 | Correct | 134 ms | 30328 KB | Output is correct |
20 | Correct | 79 ms | 17912 KB | Output is correct |
21 | Correct | 77 ms | 18552 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9728 KB | Output is correct |
2 | Correct | 6 ms | 9728 KB | Output is correct |
3 | Correct | 7 ms | 9856 KB | Output is correct |
4 | Correct | 7 ms | 9856 KB | Output is correct |
5 | Correct | 7 ms | 9984 KB | Output is correct |
6 | Correct | 7 ms | 9856 KB | Output is correct |
7 | Correct | 7 ms | 9984 KB | Output is correct |
8 | Correct | 7 ms | 9984 KB | Output is correct |
9 | Correct | 7 ms | 9856 KB | Output is correct |
10 | Correct | 7 ms | 9856 KB | Output is correct |
11 | Correct | 75 ms | 16376 KB | Output is correct |
12 | Correct | 89 ms | 18040 KB | Output is correct |
13 | Correct | 103 ms | 19960 KB | Output is correct |
14 | Correct | 127 ms | 22904 KB | Output is correct |
15 | Correct | 145 ms | 24184 KB | Output is correct |
16 | Correct | 214 ms | 27512 KB | Output is correct |
17 | Correct | 147 ms | 29176 KB | Output is correct |
18 | Correct | 184 ms | 27896 KB | Output is correct |
19 | Correct | 134 ms | 30328 KB | Output is correct |
20 | Correct | 79 ms | 17912 KB | Output is correct |
21 | Correct | 77 ms | 18552 KB | Output is correct |
22 | Correct | 185 ms | 30328 KB | Output is correct |
23 | Correct | 192 ms | 28792 KB | Output is correct |
24 | Correct | 229 ms | 29048 KB | Output is correct |
25 | Correct | 171 ms | 33272 KB | Output is correct |
26 | Correct | 168 ms | 29944 KB | Output is correct |
27 | Correct | 173 ms | 28792 KB | Output is correct |
28 | Correct | 65 ms | 13920 KB | Output is correct |
29 | Correct | 108 ms | 18680 KB | Output is correct |
30 | Correct | 111 ms | 19576 KB | Output is correct |
31 | Correct | 114 ms | 19064 KB | Output is correct |
32 | Correct | 128 ms | 24312 KB | Output is correct |