Submission #1284124

#TimeUsernameProblemLanguageResultExecution timeMemory
1284124quan606303One-Way Streets (CEOI17_oneway)C++20
0 / 100
1 ms332 KiB
/* * @Author: RMQuan * @Date: 2025-10-27 22:45:01 * @Last Modified by: RMQuan * @Last Modified time: 2025-10-28 01:53:03 */ /*idea : */ #include <bits/stdc++.h> bool M1; #define int long long #define ll long long #define INTMAX INT_MAX #define INTMIN INT_MIN #define LONGMAX LLONG_MAX #define LONGMIN LLONG_MIN #define fi first #define se second #define memfull(a,b) memset(a,b,sizeof(a)); #define endl '\n' #define TASK "TEST" #define file() if (fopen(TASK".inp","r")){freopen(TASK".inp","r",stdin); freopen(TASK".out","w",stdout);} using namespace std; const int MOD=1e9+7; const int maxn=1e5+7; const int LOG=17; vector<pair<int,int> > adj[maxn]; vector<pair<int,int> > g[maxn]; bool is_bridge[maxn]; int n,m,q,low[maxn],num[maxn],id_dfs=0; pair<int,int> edge[maxn]; int scc_id[maxn],scc=0; bool vst[maxn]; int up[maxn][LOG+1],h[maxn],ans[maxn]; void dfs(int u,int p) { low[u]=num[u]=++id_dfs; for (auto v:adj[u]) { if (v.se==p)continue; if (num[v.fi])low[u]=min(low[u],num[v.fi]); else { dfs(v.fi,v.se); low[u]=min(low[u],low[v.fi]); if (low[v.fi]==num[v.fi])is_bridge[v.se]=true; } } } void dfs_scc(int u) { scc_id[u]=scc; for (auto v:adj[u]) { if (scc_id[v.fi]||is_bridge[v.se])continue; dfs_scc(v.fi); } } int dp1[maxn],dp2[maxn]; void pre_dfs(int u,int p) { for (auto v:g[u]) { if (v.fi==p)continue; h[v.fi]=h[u]+1; up[v.fi][0]=u; for (int i=1;i<=LOG;i++)up[v.fi][i]=up[up[v.fi][i-1]][i-1]; pre_dfs(v.fi,u); } } int lca(int u,int v) { if (h[u]<h[v])swap(u,v); for (int i=LOG;i>=0;i--)if (h[up[u][i]]>=h[v])u=up[u][i]; if (u==v)return u; for (int i=LOG;i>=0;i--) { if (up[u][i]!=up[v][i]) { u=up[u][i]; v=up[v][i]; } } return up[u][0]; } void dfs_cal(int u,int p) { for (auto v:g[u]) { if (v.fi==p)continue; dfs_cal(v.fi,u); if (dp1[v.fi])ans[v.fi]=1; else if (dp2[v.fi])ans[v.fi]=2; dp1[u]+=dp1[v.fi]; dp2[u]+=dp2[v.fi]; } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); file(); cin>>n>>m; for (int i=1;i<=m;i++) { int u,v; cin>>u>>v; adj[u].push_back({v,i}); adj[v].push_back({u,i}); edge[i]={u,v}; } for (int i=1;i<=n;i++)if(!num[i])dfs(i,0); for (int i=1;i<=n;i++) { if (!scc_id[i]) { ++scc; dfs_scc(i); } } for (int i=1;i<=m;i++) { int u=scc_id[edge[i].fi]; int v=scc_id[edge[i].se]; if (u!=v) { g[u].push_back({v,i}); g[v].push_back({u,i}); } } h[0]=-1; pre_dfs(1,0); cin>>q; while (q--) { int u,v; cin>>u>>v; u=scc_id[u],v=scc_id[v]; if (u!=v) { int LCA=lca(u,v); dp1[u]++; dp1[LCA]--; dp2[v]++; dp2[LCA]--; } } dfs_cal(1,0); for (int i=1;i<=m;i++) { int u,v; tie(u,v)=edge[i]; u=scc_id[u]; v=scc_id[v]; if (u==v)cout<<"B"; else { if (h[u]<h[v]) { if (dp1[v])cout<<"L"; else if (dp2[v])cout<<"R"; else cout<<"B"; } else if (h[v]<h[u]) { if (dp1[u])cout<<"R"; else if (dp2[u])cout<<"L"; else cout<<"B"; } } } bool M2; cerr<<"-------------------------------------------------"<<endl; cerr<<"Time : "<<clock()<<" ms"<<endl; cerr<<"Memory : "<<abs(&M2-&M1)/1024/1024<<" MB"<<endl; cerr<<"-------------------------------------------------"<<endl; return 0; }

Compilation message (stderr)

oneway.cpp: In function 'int32_t main()':
oneway.cpp:25:50: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 | #define file() if (fopen(TASK".inp","r")){freopen(TASK".inp","r",stdin); freopen(TASK".out","w",stdout);}
      |                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
oneway.cpp:106:5: note: in expansion of macro 'file'
  106 |     file();
      |     ^~~~
oneway.cpp:25:81: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 | #define file() if (fopen(TASK".inp","r")){freopen(TASK".inp","r",stdin); freopen(TASK".out","w",stdout);}
      |                                                                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
oneway.cpp:106:5: note: in expansion of macro 'file'
  106 |     file();
      |     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...