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;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e5 + 5;
#define all(x) x.begin(), x.end();
#define sz(x) (int)x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
int n, m, p, comp[MAXN], vis[MAXN];
int A[MAXN], B[MAXN], active[MAXN];
int S[MAXN], E[MAXN];
vector<pii> edges[MAXN];
void dfs(int x, int c) {
comp[x] = c;
vis[x] = 1;
for(auto [viz, ind] : edges[x]) {
if(active[ind] and !vis[viz])
dfs(viz,c);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
string ans;
for(int i = 0; i < m; i++) {
cin >> A[i] >> B[i];
edges[A[i]].pb({B[i], i});
edges[B[i]].pb({A[i], i});
active[i] = 1;
ans += 'B';
}
cin >> p;
for(int i = 1; i <= p; i++)
cin >> S[i] >> E[i];
for(int i = 0; i < m; i++) {
memset(comp, 0, sizeof(comp));
memset(vis, 0, sizeof(vis));
active[i] = 0;
for(int j = 1, c = 1; j <= n; j++)
if(!vis[j]) dfs(j, c), c++;
for(int j = 1; j <= p; j++) {
if(comp[S[j]] == comp[E[j]]) continue;
if(comp[A[i]] == comp[S[j]]) ans[i] = 'R';
else ans[i] = 'L';
}
active[i] = 1;
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |