結果

問題 No.1436 Rgaph
ユーザー 沙耶花沙耶花
提出日時 2021-03-19 23:15:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,338 bytes
コンパイル時間 4,123 ms
コンパイル使用メモリ 267,176 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 18:55:39
合計ジャッジ時間 7,416 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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

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> color(N,-1);

	stack<int> Q;
	Q.push(0);
	color[0] = 0;
	bool f0 = false,f1 = false;
	
	while(Q.size()>0){
		int u = Q.top();
		Q.pop();
		rep(i,E[u].size()){
			int v = E[u][i];
			if(color[v]==-1){
				color[v] = color[u]^1;
				Q.push(v);
			}
			else{
				if(color[u]!=color[v])continue;
				if(color[u]==0)f0=true;
				else f1=true;
				
				
			}
		}
	}
	
	if(!f0||!f1){
		cout<<-1<<endl;
		return 0;
	}
	bool f = false;
	string ans = "";
	rep(i,M){
		if(color[A[i]])ans += 'R';
		else ans += 'G';
		if(!f){
			color[A[i]] ^= 1;
			f=true;
		}
	}
	cout<<ans<<endl;
	
    return 0;
}
0