제출 #1279983

#제출 시각아이디문제언어결과실행 시간메모리
1279983WH8One-Way Streets (CEOI17_oneway)C++20
0 / 100
0 ms332 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pll pair<int, int> #define mp make_pair #define pb push_back #define f first #define s second #define endl '\n' #define ld long double signed main(){ int n,m;cin>>n>>m; vector<vector<pair<int,int>>> al(n+1); vector<int> ord(n+1, -1), low(n+1, 1e9), out(n+1); vector<array<int, 2>> ed(m+1); for(int i=0;i<m;i++){ int a,b;cin>>a>>b; ed[i][0]=a, ed[i][1]=b; al[a].pb({i, 1}); al[b].pb({i, 0}); } int q; cin >> q; int t=0; vector<vector<pair<int,int>>> ep(n+1); vector<pair<int,int>> mn(n+1, {1e9, 0}), mx(n+1, {-1, 0}); for(int i=0;i<q;i++){ int a, b;cin>>a>>b; ep[a].pb({b, 0ll}); ep[b].pb({a, 1ll}); } auto dfs1 = [&](auto dfs1, int x, int p) -> void{ ord[x]=t; low[x]=min(low[x], t); t++; //~ cout<<x<<endl; for(auto [e, d]:al[x]){ if(e==p)continue; if(ord[ed[e][d]] != -1)low[x]=min(low[x], ord[ed[e][d]]); else { dfs1(dfs1, ed[e][d], e); } } out[x]=t-1; }; dfs1(dfs1, 1, m); //~ return 0; vector<bool> vis(n+1, 0); vector<int> ans(m+1, -1); auto dfs2 = [&](auto dfs2, int x, int p) -> void{ // p is parent edge, vis[x]=true; bool up=(ed[p][0]==x); if(x!=1 and ed[p][0]!=x and ed[p][1]!=x)assert(false); for(auto [point, dir] : ep[x]){ //~ printf("%lld : point %lld dir %lld , ord %lld\n", x, point,dir,ord[point]); mn[x]=min(mn[x], mp(ord[point], dir)); mx[x]=max(mx[x], mp(ord[point], dir)); } for(auto [e, i] : al[x]){ int to=ed[e][i]; if(vis[ed[e][i]])continue; dfs2(dfs2,to, e); mn[x]=min(mn[x], mn[to]); mx[x]=max(mx[x], mx[to]); } //~ printf("at %lld parent edge index %lld, ord %lld, out %lld, low %lld\n", x, p, ord[x], out[x], low[x]); //~ printf("mn %lld %lld, mx %lld %lld\n", mn[x].f, mn[x].s, mx[x].f,mx[x].s); //~ fflush(stdout); if(low[x] < ord[x])ans[p]=-1; else { if(mn[x].f < ord[x]){ ans[p]=up ^ mn[x].s; } else if(mx[x].f > out[x]){ ans[p]=up ^ mx[x].s; } else { ans[p]=-1; } } }; dfs2(dfs2, 1, m); for(int i=0;i<m;i++){ //~ cout<<ans[i]<<endl; if(ans[i]==0)cout<<'L'; else if (ans[i]==1)cout<<'R'; else cout<<'B'; //~ else assert(false); } } /* 5 4 1 2 3 2 3 4 4 5 2 1 4 5 4 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...