結果

問題 No.1023 Cyclic Tour
ユーザー square1001square1001
提出日時 2020-04-10 21:57:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 1,327 bytes
コンパイル時間 770 ms
コンパイル使用メモリ 74,660 KB
実行使用メモリ 21,260 KB
最終ジャッジ日時 2023-10-14 00:29:54
合計ジャッジ時間 13,335 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,016 KB
testcase_01 AC 4 ms
8,020 KB
testcase_02 AC 4 ms
8,060 KB
testcase_03 AC 5 ms
8,100 KB
testcase_04 AC 136 ms
16,304 KB
testcase_05 AC 138 ms
16,368 KB
testcase_06 AC 168 ms
17,512 KB
testcase_07 AC 156 ms
16,996 KB
testcase_08 AC 122 ms
14,648 KB
testcase_09 AC 119 ms
14,664 KB
testcase_10 AC 122 ms
14,792 KB
testcase_11 AC 130 ms
15,032 KB
testcase_12 AC 113 ms
14,552 KB
testcase_13 AC 105 ms
14,272 KB
testcase_14 AC 107 ms
14,016 KB
testcase_15 AC 108 ms
14,300 KB
testcase_16 AC 222 ms
17,464 KB
testcase_17 AC 223 ms
17,220 KB
testcase_18 AC 229 ms
17,184 KB
testcase_19 AC 220 ms
17,016 KB
testcase_20 AC 243 ms
17,356 KB
testcase_21 AC 253 ms
17,464 KB
testcase_22 AC 244 ms
17,028 KB
testcase_23 AC 246 ms
16,996 KB
testcase_24 AC 230 ms
16,940 KB
testcase_25 AC 251 ms
17,292 KB
testcase_26 AC 248 ms
17,736 KB
testcase_27 AC 237 ms
17,604 KB
testcase_28 AC 232 ms
16,676 KB
testcase_29 AC 212 ms
16,176 KB
testcase_30 AC 237 ms
16,752 KB
testcase_31 AC 225 ms
16,980 KB
testcase_32 AC 220 ms
18,276 KB
testcase_33 AC 245 ms
17,704 KB
testcase_34 AC 245 ms
16,764 KB
testcase_35 AC 268 ms
17,376 KB
testcase_36 AC 255 ms
16,992 KB
testcase_37 AC 242 ms
18,280 KB
testcase_38 AC 212 ms
16,820 KB
testcase_39 AC 243 ms
16,684 KB
testcase_40 AC 237 ms
16,780 KB
testcase_41 AC 239 ms
16,656 KB
testcase_42 AC 265 ms
17,468 KB
testcase_43 AC 215 ms
16,124 KB
testcase_44 AC 154 ms
16,328 KB
testcase_45 AC 125 ms
21,260 KB
testcase_46 AC 130 ms
20,928 KB
testcase_47 AC 144 ms
21,000 KB
testcase_48 AC 212 ms
18,028 KB
testcase_49 AC 210 ms
18,144 KB
testcase_50 AC 209 ms
18,164 KB
testcase_51 AC 211 ms
18,140 KB
testcase_52 AC 212 ms
18,204 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 (int i = 0; i < V; ++i) {
		++c[cmp[i]];
	}
	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] >= c[i] && c[i] >= 2) ok = true;
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}
0