Submission #631659

#TimeUsernameProblemLanguageResultExecution timeMemory
631659NintsiChkhaidzeOne-Way Streets (CEOI17_oneway)C++14
0 / 100
8 ms10964 KiB
#include <bits/stdc++.h> #define s second #define f first #define pb push_back using namespace std; const int N = 100005; int tin[N],low[N],a[N],b[N],ID[N],O[N][1005],C[N][1005]; vector <int> adj[N],vec[N]; bool bridge[N],vis[N]; int k,idx,cnt; void dfs(int x,int par){ vis[x] = 1; tin[x] = low[x] = cnt++; for (int id: adj[x]){ int to = b[id]; if (to == x) to = a[id]; if (to == par) continue; if (vis[to]){ low[x] = min(low[x], tin[to]); }else{ dfs(to,x); low[x] = min(low[x], low[to]); if (low[to] > tin[x]) bridge[id] = 1; } } } void dfs1(int x){ ID[x] = idx; vis[x] = 1; for (int id: adj[x]){ int to = b[id]; if (to == x) to = a[id]; if (!vis[to] && !bridge[id]) dfs1(to); else if (!vis[to] && bridge[id]) vec[idx].pb(to); } } void dfs2(int x,int par){ vis[x] = 1; tin[x] = tin[par] + 1; for (int to: adj[x]){ if (vis[to]) continue; dfs2(to,x); for (int j = 1; j <= k; j++){ O[x][j] += O[to][j]; C[x][j] += C[to][j]; } } } int main (){ ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); int n,m; cin>>n>>m; for (int i = 1; i <= m; i++){ cin>>a[i]>>b[i]; adj[a[i]].pb(i); adj[b[i]].pb(i); } for (int i= 1; i <= n; i++) if (!vis[i]) dfs(i,i); for (int i= 1; i <= n; i++) vis[i] = 0; idx = 0; for (int i = 1; i <= n; i++){ if (vis[i]) continue; idx++; dfs1(i); } for (int i = 1; i <= n; i++) adj[i].clear(); for (int i = 1; i <= n; i++) for (int x: vec[i]){ if (i == ID[x]) continue; adj[i].pb(ID[x]); // cout<<i<<" "<<ID[x]<<endl; adj[ID[x]].pb(i); } cin>>k; for (int i = 1; i <= k; i++){ int x,y; cin>>x>>y; O[ID[x]][i]++; C[ID[y]][i]++; } for (int i = 1; i <= n; i++) vis[i] = tin[i] = 0; for (int i = 1; i <= n; i++) if (!vis[i]) dfs2(i,i); for (int i = 1; i <= m; i++){ if (bridge[i] == 0) cout<<'B'; else{ int x = ID[a[i]],y = ID[b[i]],o=0,c=0; if (tin[x] > tin[y]){ for (int j = 1; j <= k; j++) if (O[x][j] && !C[x][j]) o++; else if (!O[x][j] && C[x][j]) c++; if(o && !c) cout<<'R'; else if (!o && c) cout<<'L'; else cout<<'B'; }else{ for (int j = 1; j <= k; j++) if (O[y][j] && !C[y][j]) o++; else if (!O[y][j] && C[y][j]) c++; if(o && !c) cout<<'L'; else if (!o && c) cout<<'R'; else cout<<'B'; } } } }

Compilation message (stderr)

oneway.cpp: In function 'int main()':
oneway.cpp:101:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
  101 |         vis[i] = tin[i] = 0;
      |                  ~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...