This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
struct wi{
vector<int> Q,Q2;
int pocz=0,kon=0;
int most=0;
int low=0;
bool odw=0;
int pree=0;
bool odw2=0;
int nr_do_ojca=0;
int odw3=0;
}*w;
int t[200000][2];
string wypisz="";
int pre=1;
void reku(int x,int ojc,int jaka)
{
w[x].odw=1;
w[x].pree=pre;
w[x].low=pre;
pre++;
for(int i=0;i<w[x].Q.size();i+=2)
{
int pom=w[x].Q[i];
if(w[x].Q[i+1]==jaka)
continue;
if(w[pom].odw==1)
w[x].low=min(w[x].low,w[pom].pree);
else{
reku(pom,x,w[x].Q[i+1]);
w[x].low=min(w[x].low,w[pom].low);
if(w[pom].low>w[x].pree)
w[w[x].Q[i+1]].most=1;
}
}
}
int reku2(int x,int ojc)
{
w[x].odw2=1;
int mam=w[x].pocz;
for(int i=0;i<w[x].Q2.size();i++)
{
int pom=w[x].Q2[i];
if(w[pom].odw2==0)
mam+=reku2(pom,x);
}
if(x!=ojc)
{
if(mam<0)
{
if(w[w[x].nr_do_ojca].most==1)
{
if(t[w[x].nr_do_ojca][0]==x)
wypisz[w[x].nr_do_ojca-1]='L';
else wypisz[w[x].nr_do_ojca-1]='R';
}
}
else if(mam>0)
{
int mam=w[x].nr_do_ojca;
if(w[mam].most==1)
{
if(t[mam][0]==x)
wypisz[mam-1]='R';
else wypisz[mam-1]='L';
}
}
}
return mam;
}
void reku3(int x,int ojc)
{
w[x].odw3=1;
for(int i=0;i<w[x].Q.size();i+=2)
{
int pom=w[x].Q[i];
if(pom==ojc)
continue;
if(w[pom].odw3==1)
continue;
w[x].Q2.push_back(pom);
w[pom].nr_do_ojca=w[x].Q[i+1];
reku3(pom,x);
}
}
int32_t main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
//freopen("test.in", "r", stdin);
int n,m,x,y;
cin>>n>>m;
w=new wi[max(n,m)+3];
for(int i=1;i<=m;i++)
{
cin>>x>>y;
w[x].Q.push_back(y);
w[y].Q.push_back(x);
w[x].Q.push_back(i);
w[y].Q.push_back(i);
t[i][0]=x;
t[i][1]=y;
wypisz+="B";
}
for(int i=1;i<=n;i++)
if(w[i].odw3==0)
reku3(i,0);
vector<int> poczatki;
for(int i=1;i<=n;i++)
if(w[i].odw==0)
reku(i,0,0),poczatki.push_back(i);
int zap;
cin>>zap;
while(zap--)
{
cin>>x>>y;
w[x].pocz++;
w[y].pocz--;
}
for(int i=0;i<poczatki.size();i++)
int e=reku2(poczatki[i],poczatki[i]);
cout<<wypisz;
return 0;
}
Compilation message (stderr)
oneway.cpp: In function 'void reku(int, int, int)':
oneway.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int i=0;i<w[x].Q.size();i+=2)
| ~^~~~~~~~~~~~~~
oneway.cpp: In function 'int reku2(int, int)':
oneway.cpp:43:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int i=0;i<w[x].Q2.size();i++)
| ~^~~~~~~~~~~~~~~
oneway.cpp: In function 'void reku3(int, int)':
oneway.cpp:76:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for(int i=0;i<w[x].Q.size();i+=2)
| ~^~~~~~~~~~~~~~
oneway.cpp: In function 'int32_t main()':
oneway.cpp:123:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
123 | for(int i=0;i<poczatki.size();i++)
| ~^~~~~~~~~~~~~~~~
oneway.cpp:124:13: warning: unused variable 'e' [-Wunused-variable]
124 | int e=reku2(poczatki[i],poczatki[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... |