#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
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 |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
472 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
472 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
41 ms |
14328 KB |
Output is correct |
12 |
Correct |
57 ms |
15220 KB |
Output is correct |
13 |
Correct |
72 ms |
16212 KB |
Output is correct |
14 |
Correct |
115 ms |
17108 KB |
Output is correct |
15 |
Correct |
104 ms |
17200 KB |
Output is correct |
16 |
Correct |
87 ms |
15692 KB |
Output is correct |
17 |
Correct |
74 ms |
17484 KB |
Output is correct |
18 |
Correct |
75 ms |
15700 KB |
Output is correct |
19 |
Correct |
70 ms |
18316 KB |
Output is correct |
20 |
Correct |
66 ms |
15336 KB |
Output is correct |
21 |
Correct |
64 ms |
14924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
472 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
41 ms |
14328 KB |
Output is correct |
12 |
Correct |
57 ms |
15220 KB |
Output is correct |
13 |
Correct |
72 ms |
16212 KB |
Output is correct |
14 |
Correct |
115 ms |
17108 KB |
Output is correct |
15 |
Correct |
104 ms |
17200 KB |
Output is correct |
16 |
Correct |
87 ms |
15692 KB |
Output is correct |
17 |
Correct |
74 ms |
17484 KB |
Output is correct |
18 |
Correct |
75 ms |
15700 KB |
Output is correct |
19 |
Correct |
70 ms |
18316 KB |
Output is correct |
20 |
Correct |
66 ms |
15336 KB |
Output is correct |
21 |
Correct |
64 ms |
14924 KB |
Output is correct |
22 |
Correct |
94 ms |
17352 KB |
Output is correct |
23 |
Correct |
109 ms |
16052 KB |
Output is correct |
24 |
Correct |
133 ms |
15712 KB |
Output is correct |
25 |
Correct |
89 ms |
20044 KB |
Output is correct |
26 |
Correct |
97 ms |
17188 KB |
Output is correct |
27 |
Correct |
112 ms |
16084 KB |
Output is correct |
28 |
Correct |
36 ms |
12668 KB |
Output is correct |
29 |
Correct |
87 ms |
15020 KB |
Output is correct |
30 |
Correct |
71 ms |
15024 KB |
Output is correct |
31 |
Correct |
85 ms |
15280 KB |
Output is correct |
32 |
Correct |
81 ms |
16972 KB |
Output is correct |