結果

問題 No.1023 Cyclic Tour
ユーザー square1001square1001
提出日時 2020-04-10 21:57:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,300 bytes
コンパイル時間 674 ms
コンパイル使用メモリ 74,464 KB
実行使用メモリ 21,156 KB
最終ジャッジ日時 2023-10-14 00:28:46
合計ジャッジ時間 13,197 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,032 KB
testcase_01 AC 4 ms
8,112 KB
testcase_02 AC 4 ms
8,028 KB
testcase_03 AC 5 ms
8,004 KB
testcase_04 AC 153 ms
16,360 KB
testcase_05 AC 148 ms
16,248 KB
testcase_06 AC 175 ms
17,732 KB
testcase_07 AC 159 ms
16,868 KB
testcase_08 AC 124 ms
14,648 KB
testcase_09 AC 123 ms
14,604 KB
testcase_10 AC 119 ms
14,720 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 106 ms
14,096 KB
testcase_15 WA -
testcase_16 AC 222 ms
17,256 KB
testcase_17 AC 223 ms
17,264 KB
testcase_18 AC 230 ms
17,264 KB
testcase_19 AC 214 ms
16,900 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 245 ms
17,296 KB
testcase_26 AC 251 ms
17,852 KB
testcase_27 AC 243 ms
17,528 KB
testcase_28 AC 232 ms
16,652 KB
testcase_29 AC 212 ms
16,100 KB
testcase_30 AC 230 ms
17,092 KB
testcase_31 AC 226 ms
16,972 KB
testcase_32 AC 231 ms
18,332 KB
testcase_33 AC 243 ms
17,796 KB
testcase_34 AC 241 ms
16,712 KB
testcase_35 AC 268 ms
17,384 KB
testcase_36 WA -
testcase_37 AC 237 ms
18,116 KB
testcase_38 AC 221 ms
16,636 KB
testcase_39 WA -
testcase_40 AC 241 ms
16,888 KB
testcase_41 AC 237 ms
16,912 KB
testcase_42 AC 275 ms
17,484 KB
testcase_43 AC 221 ms
16,096 KB
testcase_44 AC 162 ms
16,268 KB
testcase_45 AC 121 ms
21,140 KB
testcase_46 AC 124 ms
20,812 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 216 ms
18,128 KB
testcase_52 AC 221 ms
18,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
using namespace std;
int V, E; vector<int> G[100009], rG[100009], vs; bool used[100009]; int cmp[100009];
void add_edge(int from, int to) {
	G[from].push_back(to);
	rG[to].push_back(from);
}
void dfs(int v) {
	used[v] = true;
	for (int i = 0; i < G[v].size(); i++) {
		if (!used[G[v][i]]) dfs(G[v][i]);
	}
	vs.push_back(v);
}
void rdfs(int v, int k) {
	used[v] = true;
	cmp[v] = k;
	for (int i = 0; i < rG[v].size(); i++) {
		if (!used[rG[v][i]]) rdfs(rG[v][i], k);
	}
}
int scc() {
	fill(used, used + V, false);
	vs.clear();
	for (int v = 0; v < V; v++) {
		if (!used[v]) dfs(v);
	}
	fill(used, used + V, false);
	int k = 0;
	for (int i = vs.size() - 1; i >= 0; i--) {
		if (!used[vs[i]]) rdfs(vs[i], k++);
	}
	return k;
}
int main() {
	cin >> V >> E;
	vector<pair<int, int> > edges;
	for (int i = 0; i < E; ++i) {
		int a, b, c;
		cin >> a >> b >> c; --a, --b;
		add_edge(a, b);
		if (c == 1) add_edge(b, a);
		edges.push_back(make_pair(a, b));
	}
	int z = scc();
	vector<int> d(z), c(z);
	for (pair<int, int> e : edges) {
		if (cmp[e.first] == cmp[e.second]) {
			++d[cmp[e.first]];
			++c[cmp[e.first]];
		}
	}
	bool ok = false;
	for (int i = 0; i < z; ++i) {
		if (d[i] >= c[i] && c[i] >= 2) ok = true;
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}
0