이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define szz(r) (ll)r.size()
#define vi vector<int>
#define vvi vector<vi>
#define pp pair<ll,int>
#define ub(x,i) upper_bound(all(x),i)-x.begin()
using namespace std;
const int mxn=3e5+5;
vector<pair<int,pii>>g[mxn],gr[mxn];
pii rd[mxn];
int ans[mxn]{0};
int di[mxn]{0},lo[mxn]{0},cur=0;
bool vis[mxn]{0};
int id[mxn]{0},cc=1;
stack<int>st;
vector<int>qr[mxn];
map<int,int>mp[2][mxn];
void dfs(int u,int rd){
di[u]=lo[u]=++cur;vis[u]=1;
st.push(u);
for(auto [v,w]:g[u]){
if(w.f==rd)continue;
if(!di[v])dfs(v,w.f);
if(vis[v])lo[u]=min(lo[u],lo[v]);
}
if(lo[u]==di[u]){
while(st.top()!=u){
int v=st.top();st.pop();
id[v]=cc;vis[v]=0;
}id[u]=cc;cc++;st.pop();vis[u]=0;
}
}
int cn1=0,cn2=0;
bool vv[mxn]{0};
int solve(int u,int rd,int xo){
vis[u]=1;
int rs=0;
for(auto [v,w]:gr[u]){
if(vis[v])continue;
rs+=solve(v,w.f,w.s);
}
for(auto it : qr[u]){
if(it<0)rs--;
else rs++;
}
if(rd==-1)return 0;
if(rs==0)ans[rd]=2;
else if(rs>0)ans[rd]=xo;
else if(rs<0)ans[rd]=xo^1;
return rs;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,m;cin>>n>>m;
for(int i=0;i<m;i++){
cin>>rd[i].f>>rd[i].s;
if(rd[i].f==rd[i].s){ans[i]=2;continue;}
g[rd[i].f].pb({rd[i].s,{i,0}});g[rd[i].s].pb({rd[i].f,{i,1}});
}
for(int i=1;i<=n;i++){
if(!di[i])dfs(i,-1);
}
for(int i=1;i<=n;i++){
for(auto [v,w]:g[i]){
if(id[i]==id[v])ans[w.f]=2;
else gr[id[i]].pb({id[v],{w.f,w.s}}),gr[id[v]].pb({id[i],{w.f,w.s^1}});
}
}
int p;cin>>p;
for(int i=1;i<=p;i++){
int x,y;cin>>x>>y;
if(id[x]==id[y])continue;
qr[id[x]].pb(i);
qr[id[y]].pb(-i);
}memset(vis,0,sizeof vis);
for(int i=1;i<=cc;i++){
if(!vis[i])solve(i,-1,-1);
}
for(int i=0;i<m;i++){
if(ans[i]==2)cout<<'B';
if(ans[i]==1)cout<<'R';
if(ans[i]==0)cout<<'L';
}
}
컴파일 시 표준 에러 (stderr) 메시지
oneway.cpp: In function 'void dfs(int, int)':
oneway.cpp:29:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
29 | for(auto [v,w]:g[u]){
| ^
oneway.cpp: In function 'int solve(int, int, int)':
oneway.cpp:46:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
46 | for(auto [v,w]:gr[u]){
| ^
oneway.cpp: In function 'int main()':
oneway.cpp:74:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
74 | for(auto [v,w]:g[i]){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |