제출 #161568

#제출 시각아이디문제언어결과실행 시간메모리
161568shayan_pOne-Way Streets (CEOI17_oneway)C++14
0 / 100
11 ms10236 KiB
// Remember... #include<bits/stdc++.h> #define F first #define S second #define PB push_back #define sz(s) int((s).size()) #define bit(n,k) (((n)>>(k))&1) using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const int maxn=1e5+10,mod=1e9+7; const ll inf=1e18; vector<pii> v[maxn], g[maxn]; int C, h[maxn], hh[maxn]; bool mark[maxn]; int ans[maxn], who[maxn]; void prep(int u,int par=-1){ mark[u]=1; hh[u]= h[u]; for(auto p:v[u]){ if(p.S!=par){ if(mark[p.F]) hh[u]=min(hh[u], h[p.F]); else h[p.F]= h[u]+1, prep(p.F,p.S), hh[u]=min(hh[u], hh[p.F]); } } } void buildg(int u,int id){ who[u]=id; mark[u]=1; for(auto p:v[u]){ if(mark[p.F]==0){ if(hh[p.F]==h[p.F]) g[id].PB({++C,p.S}), buildg(p.F,C); else buildg(p.F,id); } } } map<int,bool> mp[maxn]; void dfs(int u,int par=-1){ for(auto p:g[u]){ if(p.S!=par){ dfs(p.F,p.S); if(sz(mp[u]) < sz(mp[p.F])) swap(mp[u],mp[p.F]); for(auto pp:mp[p.F]){ if(mp[u].count(pp.F)) mp[u].erase(pp.F); else mp[u][pp.F]=pp.S; } mp[p.F].clear(); } } if(!mp[u].empty() && (mp[u].begin()->S)) ans[par]=1; if(!mp[u].empty() && !(mp[u].begin()->S)) ans[par]=0; } vector<pii> ed; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(); memset(ans,-1,sizeof ans); int n,m; cin>>n>>m; for(int i=0;i<m;i++){ int a,b; cin>>a>>b; v[a].PB({b,i}); v[b].PB({a,i}); ed.PB({a,b}); } prep(1); memset(mark,0,sizeof mark); buildg(1,++C); int q; cin>>q; for(int i=0;i<q;i++){ int a,b; cin>>a>>b; a=who[a], b=who[b]; if(a!=b){ mp[a][i]=1, mp[b][i]=0; } } dfs(1); for(int i=0;i<m;i++){ if(ans[i]==-1) cout<<'B'; else if((ans[i]) ^ (h[ed[i].F] > h[ed[i].S])) cout<<'L'; else cout<<'R'; } return cout<<endl,0; } // Deathly mistakes: // * Read the problem carefully. // * Check maxn. // * Overflows. // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...