結果

問題 No.1436 Rgaph
ユーザー 沙耶花沙耶花
提出日時 2021-03-19 23:22:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,287 bytes
コンパイル時間 4,516 ms
コンパイル使用メモリ 266,820 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 19:08:31
合計ジャッジ時間 9,418 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 13 ms
5,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001


unsigned long xor128() {
	static unsigned long x=123456789, y=362436069, z=521288629, w=88675123;
	unsigned long t=(x^(x<<11));
	x=y; y=z; z=w;
	return (w=(w^(w>>19))^(t^(t>>8)));
}

int main(){
	
	int N,M;
	cin>>N>>M;
	
	vector<int> A(M),B(M);
	vector<vector<int>> E(N);
	rep(i,M){
		cin>>A[i]>>B[i];
		A[i]--;B[i]--;
		E[A[i]].push_back(B[i]);
	}
	
	rep(i,N){
		vector<bool> visited(N,false);
		visited[i] = true;
		queue<int> Q;
		Q.push(i);
		while(Q.size()>0){
			int u = Q.front();
			Q.pop();
			
			rep(j,E[u].size()){
				int v = E[u][j];
				if(visited[v])continue;
				visited[v] = true;
				Q.push(v);
			}
		}
		
		rep(j,N){
			if(!visited[j]){
				cout<<-1<<endl;
				return 0;
			}
		}
	}
	
	vector<int> dis(N,Inf);

	stack<int> Q;
	int X = xor128()%N;
	Q.push(X);
	dis[X] = 0;
	
	while(Q.size()>0){
		int u = Q.top();
		Q.pop();
		rep(i,E[u].size()){
			int v = E[u][i];
			if(dis[v]==Inf)continue;
			dis[v] = dis[u] + 1;
			Q.push(v);
		}
	}
	string t = "RBBR";
	string ans = "";
	rep(i,M){
		ans += t[dis[A[i]]%4];
	}
	cout<<ans<<endl;
	
    return 0;
}
0