Submission #138924

# Submission time Handle Problem Language Result Execution time Memory
138924 2019-07-31T00:26:48 Z liwi One-Way Streets (CEOI17_oneway) C++11
0 / 100
9 ms 5624 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 100005
#define MAXM 100005
#define LOGN 20

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

mt19937 g1(time(0));

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int num_nodes,num_edges,num_q,dlow[MAXN],dnum[MAXN],par[MAXN],par2[MAXN],par_e[MAXN],group[MAXN],path[MAXN],depth[MAXN],st[MAXN][LOGN],up[MAXN],down[MAXN],ans[MAXM],ncnt,scnt;
bool is_bridge[MAXM],vis[MAXN],isrt[MAXN];
vector<pii> bc[MAXN],g2[MAXN];
vector<pii> edges;

void tarjans(int node){
	dlow[node] = dnum[node] = ++ncnt;
	for(pii check:bc[node]){
		if(dnum[check.first] == 0){
			par[check.first] = node;
			tarjans(check.first);
			if(dlow[check.first] > dnum[node])
				is_bridge[check.second] = true;
			dlow[node] = min(dlow[node],dlow[check.first]);
		}else if(check.first != par[node])
			dlow[node] = min(dlow[node],dnum[check.first]);
	}
}

void build_graph(int node){
	int curr = ++scnt;
	queue<int> q;
	q.push(node);
	vis[node] = true;
	while(q.size()){
		int n = q.front(); q.pop();
		group[n] = curr;
		for(pii check:bc[n]){
			if(vis[check.first]) continue;
			if(is_bridge[check.second]){
				build_graph(check.first);
				g2[curr].pb(mp(group[check.first],check.second));
				g2[group[check.first]].pb(mp(curr,check.second));
			}else{
				vis[check.first] = true;
				q.push(check.first);
			}
		}
	}
}

void dfs(int node, int prev, int d){
	path[d] = node;
	depth[node] = d;
	for(pii check:g2[node]){
		if(check.first == prev) continue;
		par_e[check.first] = check.second;
		par2[check.first] = node;
		dfs(check.first,node,d+1);
	}
	for(int i=0; i<LOGN; i++){
		int nxt = 1<<i;
		if(d < nxt) break;
		st[node][i] = path[d-nxt];
	}
}

int lca(int a, int b){
	if(depth[a] > depth[b]) swap(a,b);
	int diff = depth[b]-depth[a];
	for(int i=0; i<LOGN; i++)
		if(diff&(1<<i))
			b = st[b][i];
	if(a == b) return a;
	for(int i=LOGN-1; i>=0; i--)
		if(st[a][i] != -1 && st[b][i] != -1 && st[a][i] != st[b][i])
			a = st[a][i], b = st[b][i];
	return st[a][0];
}

void solve(int node, int prev){
	vis[node] = true;
	for(pii check:g2[node]){
		if(check.first == prev) continue;
		solve(check.first,node);
		up[node]+=up[check.first];
		down[node]+=down[check.first];
	}
	assert(!(up[node]&&down[node]));
	if(up[node]) ans[par_e[node]] = 1;
	else if(down[node]) ans[par_e[node]] = 2;
}

int main(){
	scanf("%d %d",&num_nodes,&num_edges);
	for(int i=1; i<=num_edges; i++){
		int a,b; scanf(" %d %d",&a,&b);
		bc[a].pb(mp(b,i));
		bc[b].pb(mp(a,i));
		edges.pb(mp(a,b));
	}
	for(int i=1; i<=num_nodes; i++){
		if(vis[i]) continue;
		tarjans(i);
		build_graph(i);
		dfs(group[i],-1,0);
		isrt[group[i]] = true;
	}
//	for(int i=1; i<=num_nodes; i++) printf("%d ",group[i]); printf("\n");
	scanf(" %d",&num_q);
	for(int i=1; i<=num_q; i++){
		int a,b,lc; scanf(" %d %d",&a,&b);
		a = group[a], b = group[b], lc = lca(a,b);
		up[a]++, up[lc]--;
		down[b]++, down[lc]--;
	}
	memset(vis,false,sizeof vis);
	for(int i=1; i<=scnt; i++){
		if(!isrt[i]) continue;
		solve(i,-1);
	}
//	printf("%d %d\n",up[10],down[10]);
//	printf("%d\n",par2[9]);
	for(int i=1; i<=num_edges; i++){
//		printf("%d ",ans[i]);
		int a = group[edges[i-1].first], b = group[edges[i-1].second];
		if(ans[i] == 0) printf("B");
		else if(ans[i] == 1){
			if(par2[a] == b) printf("R");
			else printf("L");
		}else{
			if(par2[a] == b) printf("L");
			else printf("R");
		}
	}
}
/*
4 4
1 2
2 3
2 4
3 4
2
1 3
1 4
ans=RBBB
 */

Compilation message

oneway.cpp: In function 'int main()':
oneway.cpp:131:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&num_nodes,&num_edges);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
oneway.cpp:133:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a,b; scanf(" %d %d",&a,&b);
            ~~~~~^~~~~~~~~~~~~~~~
oneway.cpp:146:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf(" %d",&num_q);
  ~~~~~^~~~~~~~~~~~~~
oneway.cpp:148:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a,b,lc; scanf(" %d %d",&a,&b);
               ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5240 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 8 ms 5240 KB Output is correct
4 Correct 7 ms 5368 KB Output is correct
5 Correct 8 ms 5624 KB Output is correct
6 Correct 7 ms 5352 KB Output is correct
7 Correct 9 ms 5624 KB Output is correct
8 Correct 7 ms 5368 KB Output is correct
9 Incorrect 7 ms 5240 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5240 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 8 ms 5240 KB Output is correct
4 Correct 7 ms 5368 KB Output is correct
5 Correct 8 ms 5624 KB Output is correct
6 Correct 7 ms 5352 KB Output is correct
7 Correct 9 ms 5624 KB Output is correct
8 Correct 7 ms 5368 KB Output is correct
9 Incorrect 7 ms 5240 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5240 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 8 ms 5240 KB Output is correct
4 Correct 7 ms 5368 KB Output is correct
5 Correct 8 ms 5624 KB Output is correct
6 Correct 7 ms 5352 KB Output is correct
7 Correct 9 ms 5624 KB Output is correct
8 Correct 7 ms 5368 KB Output is correct
9 Incorrect 7 ms 5240 KB Output isn't correct
10 Halted 0 ms 0 KB -