Submission #954471

#TimeUsernameProblemLanguageResultExecution timeMemory
954471koukirocksOne-Way Streets (CEOI17_oneway)C++17
100 / 100
72 ms18548 KiB
#include <bits/stdc++.h> #define speed ios_base::sync_with_stdio(0); cin.tie(0) #define all(x) (x).begin(),(x).end() #define F first #define S second //#pragma GCC optimize("O3") //#pragma GCC target("avx,avx2") //#pragma GCC target("popcnt") namespace{using namespace std;} typedef long long ll; typedef double db; typedef long double ldb; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const ll MAX=1e5+10,P=1e9+7; const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f; const ldb eps=1e-6; int n,m,pr; vector<pii> G[MAX]; vector<pii> eg; int dfn[MAX]; int tme=1; int low[MAX]; int fa[MAX]; int st[MAX],ed[MAX]; bool vis[MAX]; vector<int> l,r; void dfsid(int v,int p,int pid) { fa[v]=pid; dfn[v]=tme++; for (auto [i,id]:G[v]) { if (i==p) { p=-1; continue; } if (dfn[i]!=-1) continue; if (vis[i]) continue; dfsid(i,v,id); st[v]+=st[i]; ed[v]+=ed[i]; } vis[v]=true; } void dfslow(int v,int p) { // cout<<v<<" "<<p<<" vp\n"; low[v]=v; for (auto [i,id]:G[v]) { if (i==p) { p=-1; continue; } if (dfn[i]<dfn[v]) { // cout<<v<<" "<<i<<" vi\n"; if (dfn[i]<dfn[low[v]]) low[v]=i; continue; } if (vis[i]) continue; dfslow(i,v); if (dfn[low[i]]<dfn[low[v]]) low[v]=low[i]; } vis[v]=true; } void dfsans(int v,int p) { if (low[v]==v and v!=1) { // cout<<v<<" bg\n"; if (st[v]>ed[v]) { auto [a,b]=eg[fa[v]]; if (v==a) r.push_back(fa[v]); else l.push_back(fa[v]); } if (st[v]<ed[v]) { auto [a,b]=eg[fa[v]]; if (v==b) r.push_back(fa[v]); else l.push_back(fa[v]); } } for (auto [i,id]:G[v]) { if (i==p) { p=-1; continue; } if (dfn[i]<dfn[v]) continue; if (vis[i]) continue; dfsans(i,v); } vis[v]=true; } int main() { speed; cin>>n>>m; eg.emplace_back(0,0); for (int i=1;i<=m;i++) { int a,b; cin>>a>>b; eg.emplace_back(a,b); if (a==b) continue; G[a].emplace_back(b,i); G[b].emplace_back(a,i); } memset(st,0,sizeof(st)); memset(ed,0,sizeof(ed)); cin>>pr; for (int i=0;i<pr;i++) { int a,b; cin>>a>>b; st[a]++; ed[b]++; } memset(dfn,-1,sizeof(dfn)); memset(vis,0,sizeof(vis)); for (int i=1;i<=n;i++) { if (!vis[i]) dfsid(i,0,0); } memset(vis,0,sizeof(vis)); for (int i=1;i<=n;i++) { if (!vis[i]) dfslow(i,0); } memset(vis,0,sizeof(vis)); for (int i=1;i<=n;i++) { if (!vis[i]) dfsans(i,0); } // for (int i=1;i<=n;i++) cout<<dfn[i]<<" "; // cout<<" dfn\n"; // for (int i=1;i<=n;i++) cout<<low[i]<<" "; // cout<<" low\n"; // for (int i:l) cout<<i<<" "; // cout<<" l\n"; // for (int i:r) cout<<i<<" "; // cout<<" r\n"; vector<pair<int,char> > ans; for (int i:l) ans.emplace_back(i,'L'); for (int i:r) ans.emplace_back(i,'R'); int id=0; sort(all(ans)); for (int i=1;i<=m;i++) { if (id<ans.size() and ans[id].F==i) { cout<<ans[id].S; id++; } else cout<<"B"; } return 0; } /* 6 4 1 1 1 2 3 4 5 6 4 2 2 2 1 4 3 5 6 */

Compilation message (stderr)

oneway.cpp: In function 'int main()':
oneway.cpp:143:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  143 |   if (id<ans.size() and ans[id].F==i) {
      |       ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...