#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a,b) for (int a = 0; a < (b); ++a)
#define pb push_back
#define all(t) t.begin(), t.end()
struct Krawedz
{
int a,b;
};
const int MAXN = 1e5+5, MAXM = 1e5+5;
int n = 0, m = 0, p = 0, a = 0, b = 0, korzen = 0, cnt = -1;
vector<int> krawedzie[MAXN];
Krawedz krawedz_in[MAXM];
int wyn[MAXM];
int ile_parent[MAXN];
int glebokosc[MAXN];
int low[MAXN];
int parent[MAXN];
bool czy_most[MAXN];
int w_jakiej_spojnej[MAXN];
int dp[MAXN];
bool visited[MAXN];
int res[MAXN];
inline void DFS(int v, int par)
{
low[v] = glebokosc[v];
parent[v] = par;
for(auto x : krawedzie[v])
{
if(x == par) ++ile_parent[v];
else if(glebokosc[x] == -1)
{
glebokosc[x] = glebokosc[v] + 1;
DFS(x,v);
low[v] = min(low[v],low[x]);
}
else low[v] = min(low[v],glebokosc[x]);
}
if(ile_parent[v] > 1) low[v] = min(low[v],glebokosc[v]-1);
if(v != korzen and low[v] == glebokosc[v]) czy_most[v] = true;
}
inline void DFS2(int v)
{
w_jakiej_spojnej[v] = cnt;
for(auto x : krawedzie[v]) if(w_jakiej_spojnej[x] == -1) DFS2(x);
}
inline void DFS3(int v, int par)
{
parent[v] = par;
visited[v] = true;
for(auto x : krawedzie[v])
{
if(visited[x] == false)
{
DFS3(x,v);
dp[v] += dp[x];
}
}
if(par != -1) res[v] = dp[v];
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
rep(i,m)
{
cin >> a >> b;
krawedz_in[i] = {a,b};
krawedzie[a].pb(b), krawedzie[b].pb(a);
}
for(int i = 1; i <= n; ++i) glebokosc[i] = -1;
for(int i = 1; i <= n; ++i)
{
if(glebokosc[i] == -1)
{
glebokosc[i] = 0, korzen = i;
DFS(i,0);
}
}
for(int i = 1; i <= n; ++i) krawedzie[i] = vector<int>();
rep(i,m)
{
int a = krawedz_in[i].a, b = krawedz_in[i].b;
if((czy_most[a] == true and parent[a] == b) or (czy_most[b] == true and parent[b] == a)) continue;
krawedzie[a].pb(b), krawedzie[b].pb(a);
}
for(int i = 1; i <= n; ++i) w_jakiej_spojnej[i] = -1;
for(int i = 1; i <= n; ++i)
{
if(w_jakiej_spojnej[i] == -1)
{
++cnt;
DFS2(i);
}
}
for(int i = 1; i <= n; ++i) krawedzie[i] = vector<int>();
rep(i,m)
{
int a = w_jakiej_spojnej[krawedz_in[i].a], b = w_jakiej_spojnej[krawedz_in[i].b];
if(a == b) wyn[i] = 2;
else
{
krawedzie[a].pb(b), krawedzie[b].pb(a);
}
}
cin >> p;
rep(i,p)
{
cin >> a >> b;
a = w_jakiej_spojnej[a], b = w_jakiej_spojnej[b];
++dp[a], --dp[b];
}
for(int i = 1; i <= n; ++i) if(visited[i] == false) DFS3(i,-1);
rep(i,m)
{
int a = w_jakiej_spojnej[krawedz_in[i].a], b = w_jakiej_spojnej[krawedz_in[i].b];
if(a != b)
{
if(parent[a] == b)
{
if(res[a] == 0) wyn[i] = 2;
else if(res[a] > 0) wyn[i] = 0;
else wyn[i] = 1;
}
if(parent[b] == a)
{
if(res[b] == 0) wyn[i] = 2;
else if(res[b] > 0) wyn[i] = 1;
else wyn[i] = 0;
}
}
}
rep(i,m)
{
if(wyn[i] == 0) cout << 'R';
else if (wyn[i] == 1) cout << 'L';
else cout << 'B';
}
cout << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
2 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6644 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
1 ms |
6748 KB |
Output is correct |
8 |
Correct |
1 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
2 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6644 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
1 ms |
6748 KB |
Output is correct |
8 |
Correct |
1 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6748 KB |
Output is correct |
11 |
Correct |
29 ms |
10772 KB |
Output is correct |
12 |
Correct |
35 ms |
11436 KB |
Output is correct |
13 |
Correct |
38 ms |
12504 KB |
Output is correct |
14 |
Correct |
41 ms |
13140 KB |
Output is correct |
15 |
Correct |
43 ms |
12880 KB |
Output is correct |
16 |
Correct |
38 ms |
11344 KB |
Output is correct |
17 |
Correct |
39 ms |
13004 KB |
Output is correct |
18 |
Correct |
38 ms |
11344 KB |
Output is correct |
19 |
Correct |
42 ms |
14124 KB |
Output is correct |
20 |
Correct |
32 ms |
11096 KB |
Output is correct |
21 |
Correct |
31 ms |
10824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
2 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6644 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
1 ms |
6748 KB |
Output is correct |
8 |
Correct |
1 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6748 KB |
Output is correct |
11 |
Correct |
29 ms |
10772 KB |
Output is correct |
12 |
Correct |
35 ms |
11436 KB |
Output is correct |
13 |
Correct |
38 ms |
12504 KB |
Output is correct |
14 |
Correct |
41 ms |
13140 KB |
Output is correct |
15 |
Correct |
43 ms |
12880 KB |
Output is correct |
16 |
Correct |
38 ms |
11344 KB |
Output is correct |
17 |
Correct |
39 ms |
13004 KB |
Output is correct |
18 |
Correct |
38 ms |
11344 KB |
Output is correct |
19 |
Correct |
42 ms |
14124 KB |
Output is correct |
20 |
Correct |
32 ms |
11096 KB |
Output is correct |
21 |
Correct |
31 ms |
10824 KB |
Output is correct |
22 |
Correct |
52 ms |
13904 KB |
Output is correct |
23 |
Correct |
50 ms |
12376 KB |
Output is correct |
24 |
Correct |
56 ms |
12608 KB |
Output is correct |
25 |
Correct |
53 ms |
16988 KB |
Output is correct |
26 |
Correct |
53 ms |
13708 KB |
Output is correct |
27 |
Correct |
50 ms |
12752 KB |
Output is correct |
28 |
Correct |
23 ms |
8620 KB |
Output is correct |
29 |
Correct |
44 ms |
11860 KB |
Output is correct |
30 |
Correct |
43 ms |
11856 KB |
Output is correct |
31 |
Correct |
44 ms |
12112 KB |
Output is correct |
32 |
Correct |
51 ms |
14272 KB |
Output is correct |