Submission #791010

# Submission time Handle Problem Language Result Execution time Memory
791010 2023-07-23T10:54:40 Z phoenix0423 One-Way Streets (CEOI17_oneway) C++17
100 / 100
75 ms 22792 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pll;
typedef pair<pll, ll> tll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
const int maxn = 1e5 + 5;
vector<pll> adj[maxn];
int in[maxn], low[maxn], id[maxn], cnt[maxn], dfn = 1;
int n, m, gp = 0;
stack<int> stk;
void dfs(int pos, int idx){
	in[pos] = low[pos] = dfn++;
	stk.push(pos);
	for(auto [x, index] : adj[pos]){
		if(index % m == idx % m) continue;
		if(!in[x]) dfs(x, index);
		low[pos] = min(low[pos], low[x]);
	}
	if(in[pos] == low[pos]){
		while(stk.top() != pos){
			int x = stk.top(); stk.pop();
			id[x] = gp;
		}
		stk.pop();
		id[pos] = gp;
		gp++;
	}
}
string key = "RLB";
vector<pll> nadj[maxn];
int ncnt[maxn], ans[maxn], vis[maxn];
void build_new_graph(){
	for(int i = 0; i < n; i++){
		ncnt[id[i]] += cnt[i];
		for(auto [x, idx] : adj[i]){
			if(id[x] == id[i]){
				ans[idx % m] = 2;
			}
			else nadj[id[i]].eb(id[x], idx);
		}
	}
}
void dfsans(int pos, int prev){
	vis[pos] = 1;
	for(auto [x, idx] : nadj[pos]){
		if(idx % m == prev % m) continue;
		dfsans(x, idx);
		if(ncnt[x] > 0) ans[idx % m] = (idx < m ? 1 : 0);
		else if(ncnt[x] < 0) ans[idx % m] = (idx < m ? 0 : 1);
		else ans[idx % m] = 2;
		ncnt[pos] += ncnt[x];
	}
}
void solve(){
	cin>>n>>m;
	for(int i = 0; i < m; i++){
		int a, b;
		cin>>a>>b;
		a--, b--;
		adj[a].eb(b, i);
		adj[b].eb(a, i + m);
	}
	int p;
	cin>>p;
	for(int i = 0; i < p; i++){
		int a, b;
		cin>>a>>b;
		a--, b--;
		cnt[a] ++, cnt[b] --;
	}
	//generate a cut-block-tree
	for(int i = 0; i < n; i++){
		if(!in[i]) dfs(i, -1);
	}
	build_new_graph();
	for(int i = 0; i < gp; i++){
		if(!vis[i]) dfsans(i, -1);
	}
	for(int i = 0; i < m; i++) cout<<key[ans[i]];
}
int main(void){
	fastio;
	int t = 1;
	// cin>>t;
	while(t--){
		solve();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 5032 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 2 ms 5040 KB Output is correct
7 Correct 3 ms 5164 KB Output is correct
8 Correct 3 ms 5040 KB Output is correct
9 Correct 2 ms 5040 KB Output is correct
10 Correct 2 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 5032 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 2 ms 5040 KB Output is correct
7 Correct 3 ms 5164 KB Output is correct
8 Correct 3 ms 5040 KB Output is correct
9 Correct 2 ms 5040 KB Output is correct
10 Correct 2 ms 5076 KB Output is correct
11 Correct 33 ms 11056 KB Output is correct
12 Correct 33 ms 12260 KB Output is correct
13 Correct 34 ms 13564 KB Output is correct
14 Correct 37 ms 14860 KB Output is correct
15 Correct 40 ms 15288 KB Output is correct
16 Correct 47 ms 16076 KB Output is correct
17 Correct 51 ms 18044 KB Output is correct
18 Correct 49 ms 16448 KB Output is correct
19 Correct 61 ms 19444 KB Output is correct
20 Correct 35 ms 11852 KB Output is correct
21 Correct 30 ms 11436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 5032 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5076 KB Output is correct
6 Correct 2 ms 5040 KB Output is correct
7 Correct 3 ms 5164 KB Output is correct
8 Correct 3 ms 5040 KB Output is correct
9 Correct 2 ms 5040 KB Output is correct
10 Correct 2 ms 5076 KB Output is correct
11 Correct 33 ms 11056 KB Output is correct
12 Correct 33 ms 12260 KB Output is correct
13 Correct 34 ms 13564 KB Output is correct
14 Correct 37 ms 14860 KB Output is correct
15 Correct 40 ms 15288 KB Output is correct
16 Correct 47 ms 16076 KB Output is correct
17 Correct 51 ms 18044 KB Output is correct
18 Correct 49 ms 16448 KB Output is correct
19 Correct 61 ms 19444 KB Output is correct
20 Correct 35 ms 11852 KB Output is correct
21 Correct 30 ms 11436 KB Output is correct
22 Correct 58 ms 19264 KB Output is correct
23 Correct 59 ms 17452 KB Output is correct
24 Correct 69 ms 17700 KB Output is correct
25 Correct 75 ms 22792 KB Output is correct
26 Correct 58 ms 18792 KB Output is correct
27 Correct 56 ms 17552 KB Output is correct
28 Correct 25 ms 8820 KB Output is correct
29 Correct 40 ms 12528 KB Output is correct
30 Correct 41 ms 12656 KB Output is correct
31 Correct 46 ms 13148 KB Output is correct
32 Correct 49 ms 16332 KB Output is correct