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;
const int mxN = 1e5+2;
map<int, int> eidx[mxN];
vector<int> g[mxN], dfsg[mxN], upe[mxN], doe[mxN];
int dep[mxN], dp[mxN], parent[mxN], isbridge[mxN];
bool visited[mxN];
void dfsinit(int s, int e) {
visited[s] = 1;
for (auto u : g[s]) {
if (visited[u]) {
if (u == e) continue;
if (dep[u] < dep[s]) {
upe[s].push_back(u);
}
else {
doe[s].push_back(u);
}
continue;
}
dfsg[s].push_back(u);
dep[u] = dep[s] + 1, parent[u] = s;
dfsinit(u, s);
dp[s] += dp[u];
}
}
void dfsbridge(int s, int e) {
isbridge[s] = upe[s].size() - doe[s].size();
for (auto u : dfsg[s]) {
if (u == e) continue; // ovo ne bi trebalo ista da menja lol
dfsbridge(u, s);
isbridge[s] += isbridge[u];
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, p;
cin >> n >> m;
vector<char> ans(m, 'B');
pair<int, int> e[m];
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
--u, --v;
e[i] = {u, v};
if (u == v) continue;
eidx[u][v] = eidx[v][u] = i;
g[u].push_back(v), g[v].push_back(u);
}
cin >> p;
while (p--) {
int u, v;
cin >> u >> v;
u--, v--;
dp[u]++, dp[v]--;
}
for (int i = 0; i < n; ++i) {
if (!visited[i]) {
parent[i] = i;
dfsinit(i, -1);
dfsbridge(i, -1);
}
}
for (int i = 0; i < n; ++i) {
cout << i << " down: ";
for (auto j : doe[i]) cout << j << ' ';
cout << " up: ";
for (auto j : upe[i]) cout << j << ' ';
cout << '\n';
if (isbridge[i] == 0 && parent[i] != i && dp[i] != 0) {
ans[eidx[i][parent[i]]] = ((e[eidx[i][parent[i]]].first == i) ^ (dp[i] < 0) ? 'R' : 'L');
}
}
for (auto c : ans) cout << c;
cout << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |