#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5456 KB |
Output is correct |
2 |
Correct |
2 ms |
5456 KB |
Output is correct |
3 |
Correct |
32 ms |
5456 KB |
Output is correct |
4 |
Correct |
28 ms |
5456 KB |
Output is correct |
5 |
Correct |
26 ms |
5596 KB |
Output is correct |
6 |
Correct |
20 ms |
5448 KB |
Output is correct |
7 |
Correct |
28 ms |
5456 KB |
Output is correct |
8 |
Correct |
27 ms |
5456 KB |
Output is correct |
9 |
Correct |
25 ms |
5456 KB |
Output is correct |
10 |
Correct |
19 ms |
5456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5456 KB |
Output is correct |
2 |
Correct |
2 ms |
5456 KB |
Output is correct |
3 |
Correct |
32 ms |
5456 KB |
Output is correct |
4 |
Correct |
28 ms |
5456 KB |
Output is correct |
5 |
Correct |
26 ms |
5596 KB |
Output is correct |
6 |
Correct |
20 ms |
5448 KB |
Output is correct |
7 |
Correct |
28 ms |
5456 KB |
Output is correct |
8 |
Correct |
27 ms |
5456 KB |
Output is correct |
9 |
Correct |
25 ms |
5456 KB |
Output is correct |
10 |
Correct |
19 ms |
5456 KB |
Output is correct |
11 |
Execution timed out |
3073 ms |
10064 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5456 KB |
Output is correct |
2 |
Correct |
2 ms |
5456 KB |
Output is correct |
3 |
Correct |
32 ms |
5456 KB |
Output is correct |
4 |
Correct |
28 ms |
5456 KB |
Output is correct |
5 |
Correct |
26 ms |
5596 KB |
Output is correct |
6 |
Correct |
20 ms |
5448 KB |
Output is correct |
7 |
Correct |
28 ms |
5456 KB |
Output is correct |
8 |
Correct |
27 ms |
5456 KB |
Output is correct |
9 |
Correct |
25 ms |
5456 KB |
Output is correct |
10 |
Correct |
19 ms |
5456 KB |
Output is correct |
11 |
Execution timed out |
3073 ms |
10064 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |