Submission #476358

#TimeUsernameProblemLanguageResultExecution timeMemory
476358cgiosyOne-Way Streets (CEOI17_oneway)C++17
100 / 100
53 ms9236 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int N, M, Q;
	cin>>N>>M;
	int E[M*2+2], F[M*2+2], G[N]{};
	for(int i=1; i<=M; i++) {
		int a, b;
		cin>>a>>b; --a, --b;
		E[i*2]=b, F[i*2]=G[a], G[a]=i*2;
		E[i*2+1]=a, F[i*2+1]=G[b], G[b]=i*2+1;
	}

	int A[N]{}, D[N]{}, T[N], t=0;
	char S[M+1];
	cin>>Q;
	while(Q--) {
		int i, j;
		cin>>i>>j; --i, --j;
		++D[i], --D[j];
	}
	fill(S, S+M, 'B');
	function<void(int, int)> bcc=[&](int i, int p) {
		A[i]=T[i]=++t;
		for(int e=G[i]; e; e=F[e]) if(e!=p) {
			int&j=E[e];
			if(A[j]) { T[i]=min(T[i], A[j]); continue; }
			bcc(j, e^1);
			T[i]=min(T[i], T[j]);
			D[i]+=D[j];
			if(A[i]<T[j] && D[j]) S[e-2>>1]=(e&1 ? -D[j] : D[j])>0 ? 'L' : 'R';
		}
	};
	for(int i=0; i<N; i++) if(!A[i]) bcc(i, 0);

	S[M]=0;
	cout<<S<<'\n';
}

Compilation message (stderr)

oneway.cpp: In lambda function:
oneway.cpp:33:29: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   33 |    if(A[i]<T[j] && D[j]) S[e-2>>1]=(e&1 ? -D[j] : D[j])>0 ? 'L' : 'R';
      |                            ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...