結果
問題 | No.2277 Honest or Dishonest ? |
ユーザー | magsta |
提出日時 | 2020-09-04 18:10:53 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 5,195 bytes |
コンパイル時間 | 849 ms |
コンパイル使用メモリ | 73,472 KB |
実行使用メモリ | 20,864 KB |
最終ジャッジ日時 | 2024-11-08 06:19:25 |
合計ジャッジ時間 | 7,631 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 3 ms
5,248 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 44 ms
5,248 KB |
testcase_13 | WA | - |
testcase_14 | AC | 50 ms
5,248 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 79 ms
8,448 KB |
testcase_22 | WA | - |
testcase_23 | AC | 111 ms
8,832 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 50 ms
7,040 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 53 ms
8,704 KB |
testcase_31 | AC | 100 ms
12,928 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | AC | 145 ms
16,256 KB |
testcase_35 | WA | - |
testcase_36 | AC | 84 ms
11,520 KB |
testcase_37 | AC | 124 ms
11,520 KB |
testcase_38 | AC | 24 ms
5,248 KB |
testcase_39 | AC | 37 ms
6,016 KB |
testcase_40 | WA | - |
testcase_41 | AC | 163 ms
16,896 KB |
testcase_42 | AC | 102 ms
13,440 KB |
testcase_43 | AC | 175 ms
20,736 KB |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | AC | 176 ms
20,864 KB |
testcase_50 | AC | 180 ms
20,864 KB |
testcase_51 | AC | 185 ms
20,736 KB |
testcase_52 | AC | 177 ms
20,736 KB |
ソースコード
#include <iostream> #include <vector> using namespace std; using Graph = vector<vector<int>>; // 深さ優先探索 int seen[100010], seen2[100010]; bool dfs(const Graph &G, const Graph &G_, const Graph &G2, const Graph &G2_, int v, bool HonLia) { bool flag = false; //矛盾が生じたか if (HonLia == true) seen[v] = 2; else seen[v] = 1; for (auto next_v : G[v]) { if (seen[next_v] >= 1){ if (HonLia == true && seen[next_v] == 1) flag = true; if (HonLia == false && seen[next_v] == 2) flag = true; continue; } if (HonLia == true) {if (dfs(G, G_, G2, G2_, next_v, true) == true) flag = true;} // 再帰的に探索 else {if (dfs(G, G_, G2, G2_, next_v, false) == true) flag = true;} // 再帰的に探索 } for (auto next_v : G_[v]) { if (seen[next_v] >= 1){ if (HonLia == true && seen[next_v] == 2) flag = true; if (HonLia == false && seen[next_v] == 1) flag = true; continue; } if (HonLia == true) {if (dfs(G, G_, G2, G2_, next_v, false) == true) flag = true;} // 再帰的に探索 else {if (dfs(G, G_, G2, G2_, next_v, true) == true) flag = true;} // 再帰的に探索 } for (auto next_v : G2[v]) { if (seen[next_v] >= 1){ if (HonLia == true && seen[next_v] == 1) flag = true; if (HonLia == false && seen[next_v] == 2) flag = true; continue; } if (HonLia == true) {if (dfs(G, G_, G2, G2_, next_v, true) == true) flag = true;} // 再帰的に探索 else {if (dfs(G, G_, G2, G2_, next_v, false) == true) flag = true;} // 再帰的に探索 } for (auto next_v : G2_[v]) { if (seen[next_v] >= 1){ if (HonLia == true && seen[next_v] == 2) flag = true; if (HonLia == false && seen[next_v] == 1) flag = true; continue; } if (HonLia == true) {if (dfs(G, G_, G2, G2_, next_v, false) == true) flag = true;} // 再帰的に探索 else {if (dfs(G, G_, G2, G2_, next_v, true) == true) flag = true;} // 再帰的に探索 } return flag; } bool dfs2(const Graph &G, const Graph &G_, const Graph &G2, const Graph &G2_, int v, bool HonLia) { bool flag = false; //矛盾が生じたか if (HonLia == true) seen2[v] = 2; else seen2[v] = 1; for (auto next_v : G[v]) { if (seen2[next_v] >= 1){ if (HonLia == true && seen2[next_v] == 1) flag = true; if (HonLia == false && seen2[next_v] == 2) flag = true; continue; } if (HonLia == true) {if (dfs2(G, G_, G2, G2_, next_v, true) == true) flag = true;} // 再帰的に探索 else {if (dfs2(G, G_, G2, G2_, next_v, false) == true) flag = true;} // 再帰的に探索 } for (auto next_v : G_[v]) { if (seen2[next_v] >= 1){ if (HonLia == true && seen2[next_v] == 2) flag = true; if (HonLia == false && seen2[next_v] == 1) flag = true; continue; } if (HonLia == true) {if (dfs2(G, G_, G2, G2_, next_v, false) == true) flag = true;} // 再帰的に探索 else {if (dfs2(G, G_, G2, G2_, next_v, true) == true) flag = true;} // 再帰的に探索 } for (auto next_v : G2[v]) { if (seen2[next_v] >= 1){ if (HonLia == true && seen2[next_v] == 1) flag = true; if (HonLia == false && seen2[next_v] == 2) flag = true; continue; } if (HonLia == true) {if (dfs2(G, G_, G2, G2_, next_v, true) == true) flag = true;} // 再帰的に探索 else {if (dfs2(G, G_, G2, G2_, next_v, false) == true) flag = true;} // 再帰的に探索 } for (auto next_v : G2_[v]) { if (seen2[next_v] >= 1){ if (HonLia == true && seen2[next_v] == 2) flag = true; if (HonLia == false && seen2[next_v] == 1) flag = true; continue; } if (HonLia == true) {if (dfs2(G, G_, G2, G2_, next_v, false) == true) flag = true;} // 再帰的に探索 else {if (dfs2(G, G_, G2, G2_, next_v, true) == true) flag = true;} // 再帰的に探索 } return flag; } int main() { // 頂点数と辺数 int N, Q; cin >> N >> Q; // グラフ入力受取 Graph G(N), G_(N), G2(N), G2_(N); for (int i = 0; i < Q; ++i) { int a, b, c; cin >> a >> b >> c; if (c == 0) G[a - 1].push_back(b - 1); if (c == 1) G_[a - 1].push_back(b - 1); if (c == 0) G2[b - 1].push_back(a - 1); if (c == 1) G2_[b - 1].push_back(a - 1); } // 全頂点が訪問済みになるまで探索 long long ans = 1; for (int i = 0; i < N; i++) seen[i] = seen2[i] = 0; for (int v = 0; v < N; ++v) { if (seen[v] >= 1) continue; // v が探索済みだったらスルー long long count = 0; if (dfs(G, G_, G2, G2_, v, true) == false) count++; // v が未探索なら v を始点とした DFS を行う if (dfs2(G, G_, G2, G2_, v, false) == false) count++; // v が未探索なら v を始点とした DFS を行う ans = (ans * count) % 1000000007; } cout << ans << endl; }