# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
585282 | 2022-06-28T14:18:59 Z | hibiki | One-Way Streets (CEOI17_oneway) | C++11 | 2 ms | 2644 KB |
#include<bits/stdc++.h> using namespace std; #define pb push_back #define f first #define s second #define sz(x) (int)x.size() #define all(x) x.begin(),x.end() int n,m,p; int ind[100005], edge[100005]; int l[100005], r[100005], cnt[100005], ask[100005], ans[100005], par[100005]; vector<int> v[100005]; bool reach[100005]; vector<int> leaves; void dfs(int nw, int fa) { if(sz(v[nw]) == 1 && v[nw][0] == fa) leaves.pb(nw); par[nw] = fa; ind[fa]++; for(auto idx: v[nw]) { int go = nw ^ l[idx] ^ r[idx]; if(go == fa || ans[idx] == 3) continue; if(reach[go]) ans[idx] = 3, cnt[go]--, cnt[nw]++; else reach[go] = true, edge[go] = idx, dfs(go, nw); } } int main() { scanf("%d %d",&n,&m); for(int i = 0; i < m; i++) { scanf("%d %d",&l[i],&r[i]); v[l[i]].pb(i); v[r[i]].pb(i); } for(int i = 1; i <= n; i++) { if(!reach[i]) reach[i] = true, dfs(i, -1); } scanf("%d",&p); while(p--) { int a,b; scanf("%d %d",&a,&b); ask[a]++; ask[b]--; } queue<int> q; for(int i = 1; i <= n; i++) if(!ind[i]) q.push(i); while(!q.empty()) { int nw = q.front(); q.pop(); if(cnt[nw] > 0 || ask[nw] == 0) ans[edge[nw]] = 3; else if(ask[nw] > 0) { if(l[edge[nw]] ^ nw) ans[edge[nw]] = 1; else ans[edge[nw]] = 2; } else if(ask[nw] < 0) { if(l[edge[nw]] ^ nw) ans[edge[nw]] = 2; else ans[edge[nw]] = 1; } ind[par[nw]]--; if(!ind[par[nw]]) q.push(par[nw]); } char wd[] = {'0', 'L', 'R', 'B'}; for(int i = 0; i < m; i++) printf("%c",wd[ans[i]]); printf("\n"); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 2644 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 2644 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 2644 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |