結果

問題 No.1436 Rgaph
ユーザー KKT89
提出日時 2021-03-19 23:17:33
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,364 bytes
コンパイル時間 3,725 ms
コンパイル使用メモリ 204,364 KB
最終ジャッジ日時 2025-01-19 19:27:22
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 13 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

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

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m; cin >> n >> m;
	vector<int> a(m),b(m);
	vector<vector<int>> g(n);
	for(int i=0;i<m;i++){
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		g[a[i]].push_back(b[i]);
	}
	for(int i=0;i<n;i++){
		vector<vector<int>> dp(n,vector<int>(2,false));
		dp[i][0]=true;
		queue<pair<int,int>> q;
		q.push({i,0});
		while(q.size()){
			auto p=q.front(); q.pop();
			for(int t:g[p.first]){
				if(!dp[t][p.second^1]){
					dp[t][p.second^1]=1;
					q.push({t,p.second^1});
				}
			}
		}
		for(int j=0;j<n;j++){
			if(!dp[j][0]){
				printf("-1\n");
				return 0;
			}
		}
	}
	vector<int> col(m,-1);
	// 赤の方が丁度1個多いサイクルと緑の方が丁度1個多いサイクルがあれば後はなんでもOKな気がしている
	// 前提より全体で強連結になってるはずなので(多分)
	// 2つのサイクル同士で辺を共有する場合もありそうで難しい(サンプル1)
	if(n==m){
		printf("-1\n");
		return 0;
	}
	// return 1;
	// for(int i=0;i<m;i++){
	// 	if(col[i]!=0)printf("R");
	// 	else printf("G");
	// }
	// printf("\n");
	printf("-1\n");
}
0