結果

問題 No.1436 Rgaph
ユーザー 👑 kmjpkmjp
提出日時 2021-03-19 23:52:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,896 bytes
コンパイル時間 2,157 ms
コンパイル使用メモリ 210,340 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-04-29 19:50:13
合計ジャッジ時間 6,493 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 6 ms
7,552 KB
testcase_02 AC 5 ms
7,552 KB
testcase_03 AC 5 ms
7,296 KB
testcase_04 AC 4 ms
7,424 KB
testcase_05 WA -
testcase_06 AC 51 ms
7,552 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 55 ms
7,552 KB
testcase_12 AC 51 ms
7,552 KB
testcase_13 AC 5 ms
7,680 KB
testcase_14 AC 50 ms
7,680 KB
testcase_15 AC 27 ms
7,552 KB
testcase_16 AC 50 ms
7,552 KB
testcase_17 AC 5 ms
7,680 KB
testcase_18 AC 5 ms
7,552 KB
testcase_19 AC 5 ms
7,680 KB
testcase_20 AC 10 ms
7,424 KB
testcase_21 WA -
testcase_22 AC 19 ms
7,808 KB
testcase_23 AC 19 ms
7,552 KB
testcase_24 AC 23 ms
7,808 KB
testcase_25 WA -
testcase_26 AC 28 ms
8,320 KB
testcase_27 AC 30 ms
8,320 KB
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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[2][1010];
int ok[2020][2];
string S;

int id[1010][1010];
int cnt[1010][1010];

vector<int> R[1010];
int vis[1010];
vector<int> path;

void dfs(int cur,int start,int depth) {
	if(cur==start&&depth) {
		R[depth]=path;
		return;
	}
	if(vis[cur]!=-1) return;
	vis[cur]=depth;
	path.push_back(cur);
	FORR(e,E[0][cur]) dfs(e,start,depth+1);
	path.pop_back();
	vis[cur]=-2;
}

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[0][x].push_back(y);
		E[1][y].push_back(x);
		id[x][y]=i;
	}
	S=string(M,'R');
	ok[0][0]=ok[0][1]=1;
	queue<int> Q;
	Q.push(0);
	Q.push(1);
	
	while(Q.size()) {
		int cur=Q.front()/2;
		int id=Q.front()%2;
		Q.pop();
		FORR(e,E[id][cur]) if(ok[e][id]==0) {
			ok[e][id]=1;
			Q.push(e*2+id);
		}
	}
	FOR(i,N) if(ok[i][0]==0||ok[i][1]==0) return _P("-1\n");
	FOR(i,N) {
		MINUS(vis);
		dfs(i,i,0);
	}
	
	FOR(y,N+1) FOR(x,y) if(__gcd(x,y)==1&&R[x].size()&&R[y].size()) {
		for(i=0;i<y;i+=2) {
			S[id[R[y][i]][R[y][(i+1)%y]]]='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