結果

問題 No.1436 Rgaph
ユーザー msm1993msm1993
提出日時 2021-03-23 15:21:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 2,182 bytes
コンパイル時間 2,016 ms
コンパイル使用メモリ 183,992 KB
実行使用メモリ 7,864 KB
最終ジャッジ日時 2023-08-16 17:34:15
合計ジャッジ時間 6,751 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,612 KB
testcase_01 AC 4 ms
7,496 KB
testcase_02 AC 4 ms
7,552 KB
testcase_03 AC 3 ms
7,492 KB
testcase_04 AC 4 ms
7,524 KB
testcase_05 AC 4 ms
7,488 KB
testcase_06 AC 18 ms
7,720 KB
testcase_07 AC 4 ms
7,528 KB
testcase_08 AC 3 ms
7,492 KB
testcase_09 AC 3 ms
7,492 KB
testcase_10 AC 21 ms
7,652 KB
testcase_11 AC 4 ms
7,540 KB
testcase_12 AC 4 ms
7,848 KB
testcase_13 AC 4 ms
7,668 KB
testcase_14 AC 4 ms
7,864 KB
testcase_15 AC 4 ms
7,592 KB
testcase_16 AC 4 ms
7,560 KB
testcase_17 AC 5 ms
7,592 KB
testcase_18 AC 4 ms
7,552 KB
testcase_19 AC 4 ms
7,620 KB
testcase_20 AC 7 ms
7,548 KB
testcase_21 AC 7 ms
7,544 KB
testcase_22 AC 18 ms
7,552 KB
testcase_23 AC 13 ms
7,616 KB
testcase_24 AC 19 ms
7,708 KB
testcase_25 AC 31 ms
7,584 KB
testcase_26 AC 34 ms
7,660 KB
testcase_27 AC 33 ms
7,664 KB
testcase_28 AC 4 ms
7,544 KB
testcase_29 AC 16 ms
7,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------


int N,M;
vector<int> E[1010][2];
int ok[2020][2][2];
string S;
int id[1010][1010];
vector<int> R[1010];
int from[1010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	MINUS(id);
	FOR(i,M) {
		cin>>x>>y;
		x--,y--;
		E[x][0].push_back(y);
		E[y][1].push_back(x);
		id[x][y]=i;
	}
	S=string(M,'R');
	ok[0][0][0]=ok[0][1][0]=1;
	queue<int> Q;
	Q.push(0);
	Q.push(2);
	while(Q.size()) {
		int cur=Q.front()/4;
		int id=Q.front()/2%2;
		int oe=Q.front()%2;
		Q.pop();
		FORR(e,E[cur][id]) if(ok[e][id][oe^1]==0) {
			ok[e][id][oe^1]=1;
			Q.push(e*4+id*2+(oe^1));
		}
	}
	FOR(i,N) if(ok[i][0][0]==0||ok[i][0][1]==0||ok[i][1][0]==0) return _P("-1\n");
	FOR(i,N) {
		MINUS(from);
		from[i]=i;
		queue<int> Q;
		Q.push(i);
		while(Q.size()) {
			x=Q.front();
			Q.pop();
			FORR(e,E[x][0]) {
				if(e==i) {
					vector<int> T;
					y=x;
					while(y!=i) T.push_back(y),y=from[y];
					T.push_back(i);
					reverse(ALL(T));
					R[T.size()]=T;
					break;
				}
				else if(from[e]==-1) {
					from[e]=x;
					Q.push(e);
				}
			}
		}
		
		
	}
	for(x=2;x<N;x++) if(R[x].size()) {
		vector<pair<int,int>> V;
		FORR(r,R[x]) V.push_back({E[r][0].size(),r});
		int n=x/2+1;
		sort(ALL(V));
		reverse(ALL(V));
		ZERO(from);
		FOR(i,n) from[V[i].second]=1;
		
		FOR(i,x) if(from[R[x][i]]) S[id[R[x][i]][R[x][(i+1)%x]]]='G';
		cout<<S<<endl;
		return;
		
	}
	cout<<-1<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0