結果
問題 | No.1254 補強への架け橋 |
ユーザー | siman |
提出日時 | 2024-01-08 20:16:20 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 113 ms / 2,000 ms |
コード長 | 2,083 bytes |
コンパイル時間 | 1,262 ms |
コンパイル使用メモリ | 133,680 KB |
実行使用メモリ | 26,428 KB |
最終ジャッジ日時 | 2024-09-27 19:40:30 |
合計ジャッジ時間 | 13,150 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 1 ms
6,944 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 1 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 1 ms
6,944 KB |
testcase_17 | AC | 1 ms
6,940 KB |
testcase_18 | AC | 1 ms
6,940 KB |
testcase_19 | AC | 1 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,944 KB |
testcase_22 | AC | 1 ms
6,944 KB |
testcase_23 | AC | 2 ms
6,940 KB |
testcase_24 | AC | 1 ms
6,944 KB |
testcase_25 | AC | 2 ms
6,940 KB |
testcase_26 | AC | 2 ms
6,940 KB |
testcase_27 | AC | 1 ms
6,944 KB |
testcase_28 | AC | 1 ms
6,940 KB |
testcase_29 | AC | 1 ms
6,940 KB |
testcase_30 | AC | 1 ms
6,940 KB |
testcase_31 | AC | 1 ms
6,944 KB |
testcase_32 | AC | 2 ms
6,944 KB |
testcase_33 | AC | 2 ms
6,940 KB |
testcase_34 | AC | 1 ms
6,944 KB |
testcase_35 | AC | 1 ms
6,940 KB |
testcase_36 | AC | 1 ms
6,944 KB |
testcase_37 | AC | 2 ms
6,944 KB |
testcase_38 | AC | 1 ms
6,940 KB |
testcase_39 | AC | 1 ms
6,940 KB |
testcase_40 | AC | 1 ms
6,940 KB |
testcase_41 | AC | 1 ms
6,940 KB |
testcase_42 | AC | 1 ms
6,944 KB |
testcase_43 | AC | 2 ms
6,940 KB |
testcase_44 | AC | 2 ms
6,940 KB |
testcase_45 | AC | 2 ms
6,944 KB |
testcase_46 | AC | 2 ms
6,944 KB |
testcase_47 | AC | 2 ms
6,940 KB |
testcase_48 | AC | 2 ms
6,940 KB |
testcase_49 | AC | 1 ms
6,940 KB |
testcase_50 | AC | 2 ms
6,940 KB |
testcase_51 | AC | 2 ms
6,944 KB |
testcase_52 | AC | 2 ms
6,944 KB |
testcase_53 | AC | 3 ms
6,940 KB |
testcase_54 | AC | 3 ms
6,944 KB |
testcase_55 | AC | 2 ms
6,940 KB |
testcase_56 | AC | 2 ms
6,944 KB |
testcase_57 | AC | 2 ms
6,944 KB |
testcase_58 | AC | 2 ms
6,940 KB |
testcase_59 | AC | 2 ms
6,944 KB |
testcase_60 | AC | 1 ms
6,944 KB |
testcase_61 | AC | 2 ms
6,944 KB |
testcase_62 | AC | 2 ms
6,940 KB |
testcase_63 | AC | 9 ms
6,944 KB |
testcase_64 | AC | 3 ms
6,940 KB |
testcase_65 | AC | 6 ms
6,944 KB |
testcase_66 | AC | 5 ms
6,944 KB |
testcase_67 | AC | 3 ms
6,944 KB |
testcase_68 | AC | 6 ms
6,940 KB |
testcase_69 | AC | 7 ms
6,940 KB |
testcase_70 | AC | 4 ms
6,940 KB |
testcase_71 | AC | 3 ms
6,944 KB |
testcase_72 | AC | 8 ms
6,944 KB |
testcase_73 | AC | 3 ms
6,944 KB |
testcase_74 | AC | 7 ms
6,940 KB |
testcase_75 | AC | 6 ms
6,940 KB |
testcase_76 | AC | 2 ms
6,940 KB |
testcase_77 | AC | 5 ms
6,940 KB |
testcase_78 | AC | 8 ms
6,944 KB |
testcase_79 | AC | 9 ms
6,940 KB |
testcase_80 | AC | 8 ms
6,940 KB |
testcase_81 | AC | 8 ms
6,944 KB |
testcase_82 | AC | 9 ms
6,940 KB |
testcase_83 | AC | 84 ms
17,140 KB |
testcase_84 | AC | 90 ms
16,796 KB |
testcase_85 | AC | 54 ms
11,436 KB |
testcase_86 | AC | 75 ms
15,232 KB |
testcase_87 | AC | 80 ms
16,000 KB |
testcase_88 | AC | 13 ms
6,944 KB |
testcase_89 | AC | 84 ms
17,116 KB |
testcase_90 | AC | 57 ms
12,048 KB |
testcase_91 | AC | 44 ms
10,368 KB |
testcase_92 | AC | 23 ms
7,128 KB |
testcase_93 | AC | 72 ms
14,444 KB |
testcase_94 | AC | 66 ms
13,680 KB |
testcase_95 | AC | 62 ms
13,416 KB |
testcase_96 | AC | 82 ms
16,452 KB |
testcase_97 | AC | 36 ms
9,236 KB |
testcase_98 | AC | 84 ms
16,604 KB |
testcase_99 | AC | 50 ms
11,364 KB |
testcase_100 | AC | 89 ms
17,456 KB |
testcase_101 | AC | 20 ms
6,940 KB |
testcase_102 | AC | 11 ms
6,940 KB |
testcase_103 | AC | 22 ms
6,948 KB |
testcase_104 | AC | 32 ms
8,504 KB |
testcase_105 | AC | 69 ms
14,576 KB |
testcase_106 | AC | 40 ms
9,884 KB |
testcase_107 | AC | 87 ms
17,244 KB |
testcase_108 | AC | 83 ms
16,816 KB |
testcase_109 | AC | 69 ms
14,284 KB |
testcase_110 | AC | 61 ms
13,396 KB |
testcase_111 | AC | 67 ms
14,076 KB |
testcase_112 | AC | 28 ms
7,936 KB |
testcase_113 | AC | 57 ms
12,592 KB |
testcase_114 | AC | 36 ms
9,580 KB |
testcase_115 | AC | 14 ms
6,940 KB |
testcase_116 | AC | 47 ms
10,572 KB |
testcase_117 | AC | 29 ms
8,308 KB |
testcase_118 | AC | 80 ms
16,424 KB |
testcase_119 | AC | 47 ms
11,212 KB |
testcase_120 | AC | 76 ms
15,820 KB |
testcase_121 | AC | 24 ms
7,168 KB |
testcase_122 | AC | 44 ms
10,536 KB |
testcase_123 | AC | 2 ms
6,940 KB |
testcase_124 | AC | 110 ms
26,428 KB |
testcase_125 | AC | 113 ms
26,276 KB |
ソースコード
#include <algorithm> #include <iostream> #include <vector> using namespace std; class LowLink { public: std::vector<int> ord; std::vector<int> low; std::vector <std::pair<int, int>> bridge; std::vector<int> joint_list; std::vector<bool> joint_or_not; std::vector <std::vector<int>> G; LowLink(const std::vector <std::vector<int>> &G) { ord.resize(G.size(), -1); low.resize(G.size(), -1); this->G = G; k = 0; joint_or_not.resize(G.size(), false); for (int v = 0; v < (int) G.size(); ++v) { if (ord[v] == -1) { dfs(v); } } } bool is_bridge(int u, int v) { if (ord[u] > ord[v]) { std::swap(u, v); } return ord[u] < low[v]; } bool is_joint(int v) { return std::find(joint_list.begin(), joint_list.end(), v) != joint_list.end(); } private: int k; void dfs(int v, int parent = -1) { ord[v] = k++; low[v] = ord[v]; bool is_joint = false; int cnt = 0; for (int u : G[v]) { if (u == parent) { continue; } if (ord[u] == -1) { ++cnt; dfs(u, v); low[v] = std::min(low[v], low[u]); if (parent != -1 && ord[v] <= low[u]) { is_joint = true; } if (ord[v] < low[u]) { bridge.emplace_back(std::minmax(u, v)); } } else { low[v] = std::min(low[v], ord[u]); } } if (parent == -1 && cnt > 1) { is_joint = true; } joint_or_not[v] = is_joint; if (is_joint) { joint_list.push_back(v); } } }; int main() { int N; cin >> N; vector <vector<int>> G(N + 1); vector<tuple<int, int, int>> edges; for (int i = 1; i <= N; ++i) { int a, b; cin >> a >> b; G[a].push_back(b); G[b].push_back(a); edges.emplace_back(a, b, i); } LowLink lowlink(G); vector<int> ans; for (auto e : edges) { if (not lowlink.is_bridge(get<0>(e), get<1>(e))) { ans.push_back(get<2>(e)); } } cout << ans.size() << endl; for (int a : ans) { cout << a << " "; } cout << endl; return 0; }