#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <cstring>
#include <climits>
#include <functional>
#include <cstdlib>
#include <complex>
#include <array>
#include <iomanip>
#include <bitset>
#define fileIO(name) if(fopen(name".in", "r")) {freopen(name".in", "r", stdin); freopen(name".out", "w", stdout);}
using namespace std;
const int MAXN = 1e5 + 111;
using ll = long long;
const int P = 31;
const ll mod1 = 1e9 + 7;
const ll mod2 = 998244353;
using ld = long double;
const ld EPS = 1e-5;
using pii = pair<int, int>;
const int K = 300;
int n, m, p;
vector<int> adj[MAXN];
set<int> adj_scc[MAXN];
int scc_cnt;
stack<int> st;
pair<int, int> edges[MAXN];
int tin[MAXN];
int low[MAXN];
int dist[MAXN];
int val[MAXN];
int timer;
int id[MAXN];
void tarjan(int v, int p)
{
tin[v] = low[v] = ++timer;
st.push(v);
bool multi = false;
for (auto u : adj[v])
{
if (u == p && !multi)
{
multi = true;
continue;
}
if (!tin[u])
{
tarjan(u, v);
low[v] = min(low[v], low[u]);
}
else
low[v] = min(low[v], tin[u]);
}
if (tin[v] == low[v])
{
while (st.top() != v)
{
//cout << scc_cnt << " " << st.top() << '\n';
id[st.top()] = scc_cnt;
st.pop();
}
id[st.top()] = scc_cnt;
//cout << scc_cnt << " " << st.top() << '\n';
st.pop();
scc_cnt++;
}
}
void dfs(int v, int p)
{
//cout << v << '\n';
for (auto u : adj_scc[v])
{
if (u == p)
continue;
//cout << v << " -> " << u << '\n';
dist[u] = dist[v] + 1;
dfs(u, v);
val[v] += val[u];
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
edges[i] = { a,b };
}
for (int i = 1; i <= n; i++)
if (!tin[i])
tarjan(i, i);
for (int i = 0; i < m; i++)
{
if (id[edges[i].first] != id[edges[i].second])
{
adj_scc[id[edges[i].first]].insert(id[edges[i].second]);
adj_scc[id[edges[i].second]].insert(id[edges[i].first]);
}
}
cin >> p;
for (int i = 0; i < p; i++)
{
int a, b;
cin >> a >> b;
val[id[a]]++;
val[id[b]]--;
}
for (int i = 0; i < scc_cnt; i++)
if (!dist[i])
dfs(i, i);
for (int i = 0; i < m; i++)
{
int a = id[edges[i].first];
int b = id[edges[i].second];
if (a == b)
cout << "B";
else
{
if (dist[a] > dist[b])
{
if (val[a] == 0)
cout << "B";
else if (val[a] > 0)
cout << "R";
else
cout << "L";
}
else
{
if (val[b] == 0)
cout << "B";
else if (val[b] > 0)
cout << "L";
else
cout << "R";
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
10072 KB |
Output is correct |
2 |
Correct |
3 ms |
10076 KB |
Output is correct |
3 |
Correct |
3 ms |
10076 KB |
Output is correct |
4 |
Correct |
3 ms |
10076 KB |
Output is correct |
5 |
Correct |
3 ms |
10076 KB |
Output is correct |
6 |
Correct |
3 ms |
10152 KB |
Output is correct |
7 |
Correct |
4 ms |
10076 KB |
Output is correct |
8 |
Correct |
4 ms |
10076 KB |
Output is correct |
9 |
Correct |
3 ms |
10076 KB |
Output is correct |
10 |
Correct |
3 ms |
10076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
10072 KB |
Output is correct |
2 |
Correct |
3 ms |
10076 KB |
Output is correct |
3 |
Correct |
3 ms |
10076 KB |
Output is correct |
4 |
Correct |
3 ms |
10076 KB |
Output is correct |
5 |
Correct |
3 ms |
10076 KB |
Output is correct |
6 |
Correct |
3 ms |
10152 KB |
Output is correct |
7 |
Correct |
4 ms |
10076 KB |
Output is correct |
8 |
Correct |
4 ms |
10076 KB |
Output is correct |
9 |
Correct |
3 ms |
10076 KB |
Output is correct |
10 |
Correct |
3 ms |
10076 KB |
Output is correct |
11 |
Correct |
26 ms |
14272 KB |
Output is correct |
12 |
Correct |
30 ms |
15452 KB |
Output is correct |
13 |
Correct |
32 ms |
16720 KB |
Output is correct |
14 |
Correct |
41 ms |
18512 KB |
Output is correct |
15 |
Correct |
43 ms |
19184 KB |
Output is correct |
16 |
Correct |
64 ms |
23892 KB |
Output is correct |
17 |
Correct |
63 ms |
25948 KB |
Output is correct |
18 |
Correct |
66 ms |
23892 KB |
Output is correct |
19 |
Correct |
53 ms |
27240 KB |
Output is correct |
20 |
Correct |
28 ms |
14928 KB |
Output is correct |
21 |
Correct |
27 ms |
14672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
10072 KB |
Output is correct |
2 |
Correct |
3 ms |
10076 KB |
Output is correct |
3 |
Correct |
3 ms |
10076 KB |
Output is correct |
4 |
Correct |
3 ms |
10076 KB |
Output is correct |
5 |
Correct |
3 ms |
10076 KB |
Output is correct |
6 |
Correct |
3 ms |
10152 KB |
Output is correct |
7 |
Correct |
4 ms |
10076 KB |
Output is correct |
8 |
Correct |
4 ms |
10076 KB |
Output is correct |
9 |
Correct |
3 ms |
10076 KB |
Output is correct |
10 |
Correct |
3 ms |
10076 KB |
Output is correct |
11 |
Correct |
26 ms |
14272 KB |
Output is correct |
12 |
Correct |
30 ms |
15452 KB |
Output is correct |
13 |
Correct |
32 ms |
16720 KB |
Output is correct |
14 |
Correct |
41 ms |
18512 KB |
Output is correct |
15 |
Correct |
43 ms |
19184 KB |
Output is correct |
16 |
Correct |
64 ms |
23892 KB |
Output is correct |
17 |
Correct |
63 ms |
25948 KB |
Output is correct |
18 |
Correct |
66 ms |
23892 KB |
Output is correct |
19 |
Correct |
53 ms |
27240 KB |
Output is correct |
20 |
Correct |
28 ms |
14928 KB |
Output is correct |
21 |
Correct |
27 ms |
14672 KB |
Output is correct |
22 |
Correct |
75 ms |
26996 KB |
Output is correct |
23 |
Correct |
80 ms |
25176 KB |
Output is correct |
24 |
Correct |
83 ms |
25172 KB |
Output is correct |
25 |
Correct |
67 ms |
30616 KB |
Output is correct |
26 |
Correct |
81 ms |
26704 KB |
Output is correct |
27 |
Correct |
90 ms |
25300 KB |
Output is correct |
28 |
Correct |
22 ms |
12368 KB |
Output is correct |
29 |
Correct |
42 ms |
15696 KB |
Output is correct |
30 |
Correct |
42 ms |
15800 KB |
Output is correct |
31 |
Correct |
41 ms |
16212 KB |
Output is correct |
32 |
Correct |
48 ms |
21076 KB |
Output is correct |