#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44
using namespace std;
const int MAXN = (int) 1e5;
vector < pair <int, int> > g[MAXN + 1];
int lvl[MAXN + 1], low[MAXN + 1];
int id[MAXN + 1], cnt;
stack <int> stk;
char sol[MAXN + 1];
void dfs(int nod, int par) {
lvl[nod] = lvl[par] + 1;
low[nod] = lvl[nod];
stk.push(nod);
for(auto it : g[nod]) {
if(lvl[it.first] == 0) {
dfs(it.first, nod);
low[nod] = min(low[nod], low[it.first]);
if(low[it.first] > lvl[nod]) {
cnt++;
while(stk.size() && stk.top() != it.first) {
id[stk.top()] = cnt;
stk.pop();
}
id[stk.top()] = cnt;
stk.pop();
sol[it.second] = 0;
}
}
else if(it.first != par) {
low[nod] = min(low[nod], lvl[it.first]);
}
}
}
vector < pair <int, int> > tree[MAXN + 1];
pair <int, int> edges[MAXN + 1];
bool vis[MAXN + 1];
int sp[MAXN + 1];
void dfs1(int nod, int par) {
vis[nod] = 1;
for(auto it : tree[nod]) {
if(it.first != par) {
dfs1(it.first, nod);
sp[nod] += sp[it.first];
/*cerr << it.first << " " << sp[it.first] << "\n";
cerr << nod << " " << it.first << "\n";
cerr << edges[it.second].first << " " << edges[it.second].second << "\n\n";*/
if(sp[it.first] > 0) {
if(id[edges[it.second].first] == it.first) {
sol[it.second] = 'R';
}
else {
sol[it.second] = 'L';
}
}
else if(sp[it.first] < 0) {
if(id[edges[it.second].first] == it.first) {
sol[it.second] = 'L';
}
else {
sol[it.second] = 'R';
}
}
else {
sol[it.second] = 'B';
}
}
}
}
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, n, m, q;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for(i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
edges[i] = {x, y};
g[x].push_back({y, i});
g[y].push_back({x, i});
}
memset(sol, 'B', sizeof(sol));
for(i = 1; i <= n; i++) {
if(lvl[i] == 0) {
dfs(i, 0);
}
}
cnt++;
while(stk.size()) {
id[stk.top()] = cnt;
stk.pop();
}
for(i = 1; i <= n; i++) {
for(auto it : g[i]) {
if(id[i] != id[it.first]) {
tree[id[i]].push_back({id[it.first], it.second});
}
}
}
cin >> q;
for(i = 1; i <= q; i++) {
int x, y;
cin >> x >> y;
//cerr << id[x] << " " << id[y] << "\n";
sp[id[x]]++;
sp[id[y]]--;
}
for(i = 1; i <= cnt; i++) {
if(vis[i] == 0) {
dfs1(i, 0);
}
}
for(i = 1; i <= m; i++) {
cout << sol[i];
}
//cin.close();
//cout.close();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5120 KB |
Output is correct |
2 |
Correct |
7 ms |
5120 KB |
Output is correct |
3 |
Correct |
9 ms |
5248 KB |
Output is correct |
4 |
Correct |
9 ms |
5248 KB |
Output is correct |
5 |
Correct |
8 ms |
5376 KB |
Output is correct |
6 |
Execution timed out |
3086 ms |
5248 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5120 KB |
Output is correct |
2 |
Correct |
7 ms |
5120 KB |
Output is correct |
3 |
Correct |
9 ms |
5248 KB |
Output is correct |
4 |
Correct |
9 ms |
5248 KB |
Output is correct |
5 |
Correct |
8 ms |
5376 KB |
Output is correct |
6 |
Execution timed out |
3086 ms |
5248 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5120 KB |
Output is correct |
2 |
Correct |
7 ms |
5120 KB |
Output is correct |
3 |
Correct |
9 ms |
5248 KB |
Output is correct |
4 |
Correct |
9 ms |
5248 KB |
Output is correct |
5 |
Correct |
8 ms |
5376 KB |
Output is correct |
6 |
Execution timed out |
3086 ms |
5248 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |