結果

問題 No.1023 Cyclic Tour
ユーザー square1001square1001
提出日時 2020-04-10 21:55:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,256 bytes
コンパイル時間 700 ms
コンパイル使用メモリ 74,096 KB
実行使用メモリ 21,044 KB
最終ジャッジ日時 2023-10-14 00:26:45
合計ジャッジ時間 15,826 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,324 KB
testcase_01 AC 5 ms
8,080 KB
testcase_02 AC 4 ms
8,144 KB
testcase_03 AC 4 ms
8,000 KB
testcase_04 AC 160 ms
16,416 KB
testcase_05 AC 163 ms
16,360 KB
testcase_06 AC 186 ms
17,584 KB
testcase_07 AC 161 ms
17,176 KB
testcase_08 AC 128 ms
14,432 KB
testcase_09 AC 126 ms
14,340 KB
testcase_10 AC 118 ms
14,480 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 110 ms
13,756 KB
testcase_15 WA -
testcase_16 AC 236 ms
17,208 KB
testcase_17 AC 233 ms
17,160 KB
testcase_18 AC 236 ms
17,156 KB
testcase_19 AC 231 ms
17,096 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 259 ms
17,404 KB
testcase_26 AC 262 ms
17,904 KB
testcase_27 AC 243 ms
17,676 KB
testcase_28 AC 231 ms
16,580 KB
testcase_29 AC 216 ms
15,884 KB
testcase_30 AC 241 ms
16,800 KB
testcase_31 AC 238 ms
17,144 KB
testcase_32 AC 242 ms
18,224 KB
testcase_33 AC 251 ms
17,780 KB
testcase_34 AC 244 ms
16,704 KB
testcase_35 AC 279 ms
17,440 KB
testcase_36 WA -
testcase_37 AC 244 ms
18,080 KB
testcase_38 AC 226 ms
16,664 KB
testcase_39 WA -
testcase_40 AC 244 ms
16,576 KB
testcase_41 AC 250 ms
16,604 KB
testcase_42 AC 286 ms
17,480 KB
testcase_43 AC 216 ms
15,852 KB
testcase_44 AC 152 ms
16,372 KB
testcase_45 AC 127 ms
20,812 KB
testcase_46 AC 138 ms
21,044 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 218 ms
18,136 KB
testcase_52 AC 212 ms
18,224 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);
	for (pair<int, int> e : edges) {
		if (cmp[e.first] == cmp[e.second]) {
			++d[cmp[e.first]];
		}
	}
	bool ok = false;
	for (int i = 0; i < z; ++i) {
		if (d[i] >= 2) ok = true;
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}
0