Submission #938396

# Submission time Handle Problem Language Result Execution time Memory
938396 2024-03-05T05:45:40 Z vjudge1 One-Way Streets (CEOI17_oneway) C++17
100 / 100
534 ms 69064 KB
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pb push_back
#define fr first
#define sc second
const long long INF=1e17,N=2e5+6;
vector<int> ar[N],up(N),tin(N),color(N);
vector<bool> used(N);
int timer,mxcol=0;
map<pair<int,int>,bool> mp;
map<pair<int,int>,int> e_cnt;
void bridge(int x, int p=-1){
	used[x]=1;
	tin[x]=up[x]=timer++;
	for(auto it: ar[x]){
		if(it==p) continue;
		if(used[it])
			up[x]=min(up[x],tin[it]);
		else{
			bridge(it,x);
			up[x]=min(up[x],up[it]);
			if(up[it]>tin[x]){
				mp[{it,x}]=1;
				mp[{x,it}]=1;
			}
		}
	}
}
void dfs(int x, int c){
	color[x]=c;
	used[x]=1;
	for(auto it: ar[x]){
		if(!used[it] && (!mp[{x,it}] || e_cnt[{x,it}]!=1))
			dfs(it,c);
	}
}

int n,m;
int ans[N],A[N],B[N];
map<pair<int,int>,int> edge;
vector<pair<int,int>> g[N];
int k;
int vis[N];
void DFS(int x, int p){
	vis[x]=1;
	for(auto it: g[x]){
		if(it.fr==p) continue;
		DFS(it.fr,x);
		A[x]+=A[it.fr];
		B[x]+=B[it.fr];
	}
	for(auto it: g[x]){
		if(it.fr==p) continue;
		if(A[it.fr]!=B[it.fr]){
			int t=it.sc;
			if(t<0)
				ans[-t]=1;
			else
				ans[t]=0;
			if(B[it.fr]>A[it.fr]) ans[abs(t)]^=1;
		}
	}
}
int c=0;
void get(){
	cin>>k;
	for(int i=0;i<k;i++){
		int a,b;cin>>a>>b;a--,b--;
		A[color[a]]++,B[color[b]]++;
		//DFS(color[a],color[b]);
	}
	for(int i=1;i<=c;i++)
		if(!vis[i])
			DFS(i,-1);
	for(int i=1;i<=m;i++){
		if(ans[i]==2) cout<<'B';
		else if(ans[i]==1) cout<<'R';
		else cout<<'L';
	}
}
void solve(){
	cin>>n>>m;
	vector<pair<int,int>> e;
	for(int i=0;i<m;i++){
		ans[i+1]=2;
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		e_cnt[{a,b}]++;
		e_cnt[{b,a}]++;
		ar[a].pb(b);
		ar[b].pb(a);
		edge[{a,b}]=i+1;
		edge[{b,a}]=-i-1;
		e.pb({a,b});
	}
	for(int i=0;i<n;i++){
		if(!used[i])
			bridge(i);
	}
	used.assign(N,0);
	
	for(int i=0;i<n;i++){
		if(!used[i])
			dfs(i,++c);
	}	
	for(auto it: e){
		if(color[it.fr]!=color[it.sc]){
			g[color[it.fr]].pb({color[it.sc],edge[it]});
			g[color[it.sc]].pb({color[it.fr],edge[{it.sc,it.fr}]});
		}
	}
	get();
}
main(){
	int T=1;
	//cin>>T;
	while(T--){
		solve();
	}
}

Compilation message

oneway.cpp:117:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  117 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15196 KB Output is correct
2 Correct 3 ms 15196 KB Output is correct
3 Correct 6 ms 15452 KB Output is correct
4 Correct 5 ms 15452 KB Output is correct
5 Correct 6 ms 15452 KB Output is correct
6 Correct 4 ms 15196 KB Output is correct
7 Correct 5 ms 15452 KB Output is correct
8 Correct 5 ms 15548 KB Output is correct
9 Correct 5 ms 15448 KB Output is correct
10 Correct 4 ms 15452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15196 KB Output is correct
2 Correct 3 ms 15196 KB Output is correct
3 Correct 6 ms 15452 KB Output is correct
4 Correct 5 ms 15452 KB Output is correct
5 Correct 6 ms 15452 KB Output is correct
6 Correct 4 ms 15196 KB Output is correct
7 Correct 5 ms 15452 KB Output is correct
8 Correct 5 ms 15548 KB Output is correct
9 Correct 5 ms 15448 KB Output is correct
10 Correct 4 ms 15452 KB Output is correct
11 Correct 258 ms 45588 KB Output is correct
12 Correct 265 ms 47300 KB Output is correct
13 Correct 311 ms 49828 KB Output is correct
14 Correct 363 ms 53408 KB Output is correct
15 Correct 415 ms 54616 KB Output is correct
16 Correct 511 ms 60584 KB Output is correct
17 Correct 403 ms 62664 KB Output is correct
18 Correct 504 ms 61128 KB Output is correct
19 Correct 391 ms 64392 KB Output is correct
20 Correct 298 ms 47800 KB Output is correct
21 Correct 218 ms 46284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15196 KB Output is correct
2 Correct 3 ms 15196 KB Output is correct
3 Correct 6 ms 15452 KB Output is correct
4 Correct 5 ms 15452 KB Output is correct
5 Correct 6 ms 15452 KB Output is correct
6 Correct 4 ms 15196 KB Output is correct
7 Correct 5 ms 15452 KB Output is correct
8 Correct 5 ms 15548 KB Output is correct
9 Correct 5 ms 15448 KB Output is correct
10 Correct 4 ms 15452 KB Output is correct
11 Correct 258 ms 45588 KB Output is correct
12 Correct 265 ms 47300 KB Output is correct
13 Correct 311 ms 49828 KB Output is correct
14 Correct 363 ms 53408 KB Output is correct
15 Correct 415 ms 54616 KB Output is correct
16 Correct 511 ms 60584 KB Output is correct
17 Correct 403 ms 62664 KB Output is correct
18 Correct 504 ms 61128 KB Output is correct
19 Correct 391 ms 64392 KB Output is correct
20 Correct 298 ms 47800 KB Output is correct
21 Correct 218 ms 46284 KB Output is correct
22 Correct 462 ms 62916 KB Output is correct
23 Correct 467 ms 62476 KB Output is correct
24 Correct 534 ms 62664 KB Output is correct
25 Correct 445 ms 69064 KB Output is correct
26 Correct 482 ms 64196 KB Output is correct
27 Correct 492 ms 62960 KB Output is correct
28 Correct 103 ms 19396 KB Output is correct
29 Correct 299 ms 49348 KB Output is correct
30 Correct 280 ms 49372 KB Output is correct
31 Correct 290 ms 49864 KB Output is correct
32 Correct 313 ms 51464 KB Output is correct