Submission #938987

# Submission time Handle Problem Language Result Execution time Memory
938987 2024-03-06T02:52:57 Z vjudge1 One-Way Streets (CEOI17_oneway) C++17
0 / 100
5 ms 25348 KB
#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long

using namespace std;

int pow(int a,int b,int m){int ans=1;while(b){if(b&1){ans=(ans*a)%m;}b>>=1;a=(a*a)%m;}return ans;}
int binpow(int a,int b){int ans=1;while(b){if(b&1){ans=(ans*a);}b>>=1;a=(a*a);}return ans;}
  
const int N = 2e5 + 10,  inf = 1e18;


int incyc[N], deg[N], fup[N], h[N];
vector <int> g[N], gc[N];
int lead[N];
int vis[N], par[N];
int tin[N], tout[N], up[N][25], used[N];
int timer;
map <pair <int,int>, int > brid;
void dfsc(int v){
	vis[v] = 1;
	for(auto to : g[v]){
		if(vis[to] == 0 && !brid.count({v, to})){
			lead[to] = lead[v];
			dfsc(to);
		}
	}
}

void dfs2(int v, int p = 1) {
	//cout << v <<" p"<< p << endl;
	tin[v] = ++timer;
	par[v] = p;
	up[v][0] = p;
	for (int i=1; i<=20; ++i)
		up[v][i] = up[up[v][i-1]][i-1];
	for (size_t i=0; i<gc[v].size(); ++i) {
		int to = gc[v][i];
		if (to == p)continue;
			dfs2 (to, v);
	}
	tout[v] = ++timer;
}

bool upper (int a, int b) {
	return tin[a] <= tin[b] && tout[a] >= tout[b];
}

int lca (int a, int b) {
	if (upper (a, b))  return a;
	if (upper (b, a))  return b;
	for (int i=20; i>=0; --i)
		if (! upper (up[a][i], b))
			a = up[a][i];
	return up[a][0];
}

int lift[N], desc[N];

void dfs (int v, int p = -1) {
	used[v] = true;
	tin[v] = fup[v] = timer++;
	for (size_t i=0; i<g[v].size(); ++i) {
		int to = g[v][i];
		if (to == p)  continue;
		if (used[to])
			fup[v] = min (fup[v], tin[to]);
		else {
			dfs (to, v);
			fup[v] = min (fup[v], fup[to]);
			if (fup[to] > tin[v]){
				brid[{v, to}] = 1;
				brid[{to, v}] = 1;
			}
		}
	}
}

main(){
	iostream::sync_with_stdio(false);  
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector <pair <int,int> > road;
    for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		g[a].pb(b);
		g[b].pb(a);
		road.pb({a, b});
	}
    dfs(1);
	//cout << "fin" << endl;
	for(int i = 1; i <= n; i++){
		if(lead[i] == 0){
			lead[i] = i;
			dfsc(i);
		}	
	}
	//cout << "fin2" << endl;
	for(int i = 1; i <= n; i++){
		for(auto to : g[i]){
			if(brid.count({i, to})){
				//cout << lead[i] <<"-"<< lead[to] << endl;
				gc[lead[i]].pb(lead[to]);
			}
		}
	}
	
	for(int i = 1; i <= n; i++){
		if(par[lead[i]] == 0){
			//cout <<"notvis" << lead[i] << endl;
			dfs2(lead[i], lead[i]);
		
		}
	}
	
	int p;
	cin >> p;
	map <pair <int,int>, int> mp;
	while(p--){
		int a, b;
		cin >> a >> b;
		a = lead[a];	
		b = lead[b];
		int lc = lca(a, b);
		//cout << a <<" "<< b <<" "<< lc << endl;
		while(a != lc){
			//cout << a <<"->"<< par[a]<< endl;
			if(par[a] == 0)return EXIT_FAILURE;
			mp[{a, par[a]}] = 1;
			lift[a] = 1;
			a = par[a];
		}
		while(b != lc){
			if(par[b] == 0)return EXIT_FAILURE;
			//cout <<  b <<" " << par[b]<< endl;
			mp[{par[b], b}] = 1;
			desc[b] = 1;
			b = par[b];
		}
	}
	for(auto x : road){
		int f = x.ff, s = x.ss;
		f = lead[f];
		s = lead[s];
		if(mp.count({f, s}))
			cout << 'R';
		else if(mp.count({s, f}))
			cout << 'L';
		else
			cout << 'B';
	}
}

Compilation message

oneway.cpp:84:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   84 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 25348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 25348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 25348 KB Output isn't correct
2 Halted 0 ms 0 KB -