답안 #938369

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938369 2024-03-05T05:13:26 Z vjudge1 One-Way Streets (CEOI17_oneway) C++17
0 / 100
12 ms 604 KB
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define int long long
const int N = 2e5;
const int mod = 1e9 + 7;


signed main(){
	
	int n, m; cin >> n >> m;
	
	vector<int> g[n+1];
	vector<pair<int, int> > edge;
	for(int i = 1;i <= m; i++){
		int a, b; cin >> a >> b;
		edge.push_back({a, b});
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int q; cin >> q;
	vector<pair<int, int> > Q(q);
	for(int i = 0;i < q; i++){
		cin >> Q[i].ff >> Q[i].ss;
	}
	vector<int> in(n+1, -1), out(n+1, -1);
	vector<char> ans(m, '#');
	vector<int> par(n+1);
	int timer = 1;
	map<pair<int, int>, int> mp;
	function<void(int, int)> bridges=[&](int v, int p){
		in[v] = timer;
		out[v] = timer++;
		par[v] = p;
		for(int to : g[v]){
			if(to == p) continue;
			if(in[to] == -1){
				bridges(to, v);
				out[v] = min(out[v], out[to]);
			}else{
				out[v] = min(out[v], in[to]);
			}
		}
		if(p != v && in[v] == out[v]){
			mp[make_pair(min(v, p), max(v, p))] = 1;
		}
	};
	for(int i = 1;i <= n; i++){
		if(in[i] == -1){
			bridges(i, i);
		}
	}
	for(int i = 0;i < m; i++){
		auto [a, b] = edge[i];
		if(a > b) swap(a, b);
		if(!mp.count({a, b})){
			ans[i] = 'B';
		}
	}
	vector<int> path;
	vector<int> used(n+1, 0);
	int ok = 0;
	function<void(int, int)> dfs=[&](int v, int finish){
		if(ok) return;
		path.push_back(v);
		used[v] = 1;
		if(v == finish){
			ok = 1;
			return;
		}
		for(int to : g[v]){
			if(used[to]) continue;
			dfs(to, finish);
		}
		if(ok) return;
		path.pop_back();
	};
	
	for(auto [a, b] : Q){
		path.clear();
		ok = 0;
		for(int i = 1;i <= n; i++) used[i] = 0;
		dfs(a, b);
		if(!ok) assert(false);
		set<pair<int, int> > st;
		
		for(int i = 0;i + 1 < (int)path.size(); i++){
			st.insert(make_pair(path[i], path[i+1]));
		}
		for(int i = 0;i < m; i++){
			if(ans[i] != '#') continue;
			if(st.count(edge[i])){
				ans[i] = 'R';
			}else if(st.count({edge[i].ss, edge[i].ff})){
				ans[i] = 'L';
			}
		}
		
		
	}
	
	for(int i = 0;i < m; i++){
		if(ans[i] == '#') ans[i] = 'B';
		cout << ans[i];
	}
	
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 12 ms 604 KB Output is correct
6 Correct 3 ms 444 KB Output is correct
7 Correct 9 ms 472 KB Output is correct
8 Correct 6 ms 444 KB Output is correct
9 Incorrect 3 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 12 ms 604 KB Output is correct
6 Correct 3 ms 444 KB Output is correct
7 Correct 9 ms 472 KB Output is correct
8 Correct 6 ms 444 KB Output is correct
9 Incorrect 3 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 12 ms 604 KB Output is correct
6 Correct 3 ms 444 KB Output is correct
7 Correct 9 ms 472 KB Output is correct
8 Correct 6 ms 444 KB Output is correct
9 Incorrect 3 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -