結果

問題 No.1436 Rgaph
ユーザー KKT89KKT89
提出日時 2021-03-19 23:17:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,364 bytes
コンパイル時間 3,554 ms
コンパイル使用メモリ 211,980 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 18:58:16
合計ジャッジ時間 6,785 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
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 2 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 77 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 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 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 <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