結果
問題 | No.1254 補強への架け橋 |
ユーザー | siman |
提出日時 | 2024-01-08 20:35:14 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 110 ms / 2,000 ms |
コード長 | 2,389 bytes |
コンパイル時間 | 1,370 ms |
コンパイル使用メモリ | 133,652 KB |
実行使用メモリ | 26,328 KB |
最終ジャッジ日時 | 2024-09-27 19:41:16 |
合計ジャッジ時間 | 12,332 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 1 ms
6,944 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | AC | 2 ms
6,944 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 1 ms
6,940 KB |
testcase_22 | AC | 2 ms
6,940 KB |
testcase_23 | AC | 2 ms
6,944 KB |
testcase_24 | AC | 2 ms
6,944 KB |
testcase_25 | AC | 2 ms
6,944 KB |
testcase_26 | AC | 2 ms
6,944 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | AC | 2 ms
6,944 KB |
testcase_29 | AC | 2 ms
6,940 KB |
testcase_30 | AC | 2 ms
6,944 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 2 ms
6,944 KB |
testcase_33 | AC | 2 ms
6,944 KB |
testcase_34 | AC | 2 ms
6,940 KB |
testcase_35 | AC | 2 ms
6,944 KB |
testcase_36 | AC | 2 ms
6,940 KB |
testcase_37 | AC | 2 ms
6,940 KB |
testcase_38 | AC | 2 ms
6,944 KB |
testcase_39 | AC | 2 ms
6,944 KB |
testcase_40 | AC | 2 ms
6,940 KB |
testcase_41 | AC | 1 ms
6,940 KB |
testcase_42 | AC | 2 ms
6,940 KB |
testcase_43 | AC | 2 ms
6,944 KB |
testcase_44 | AC | 2 ms
6,944 KB |
testcase_45 | AC | 2 ms
6,940 KB |
testcase_46 | AC | 2 ms
6,944 KB |
testcase_47 | AC | 2 ms
6,940 KB |
testcase_48 | AC | 2 ms
6,944 KB |
testcase_49 | AC | 2 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 | 2 ms
6,944 KB |
testcase_54 | AC | 3 ms
6,944 KB |
testcase_55 | AC | 2 ms
6,944 KB |
testcase_56 | AC | 2 ms
6,940 KB |
testcase_57 | AC | 2 ms
6,940 KB |
testcase_58 | AC | 2 ms
6,940 KB |
testcase_59 | AC | 2 ms
6,944 KB |
testcase_60 | AC | 2 ms
6,948 KB |
testcase_61 | AC | 2 ms
6,940 KB |
testcase_62 | AC | 2 ms
6,944 KB |
testcase_63 | AC | 7 ms
6,944 KB |
testcase_64 | AC | 3 ms
6,940 KB |
testcase_65 | AC | 5 ms
6,940 KB |
testcase_66 | AC | 4 ms
6,944 KB |
testcase_67 | AC | 2 ms
6,944 KB |
testcase_68 | AC | 5 ms
6,940 KB |
testcase_69 | AC | 6 ms
6,944 KB |
testcase_70 | AC | 3 ms
6,944 KB |
testcase_71 | AC | 3 ms
6,940 KB |
testcase_72 | AC | 6 ms
6,944 KB |
testcase_73 | AC | 4 ms
6,944 KB |
testcase_74 | AC | 6 ms
6,944 KB |
testcase_75 | AC | 5 ms
6,944 KB |
testcase_76 | AC | 2 ms
6,940 KB |
testcase_77 | AC | 4 ms
6,944 KB |
testcase_78 | AC | 6 ms
6,940 KB |
testcase_79 | AC | 7 ms
6,940 KB |
testcase_80 | AC | 6 ms
6,940 KB |
testcase_81 | AC | 6 ms
6,944 KB |
testcase_82 | AC | 6 ms
6,940 KB |
testcase_83 | AC | 81 ms
17,036 KB |
testcase_84 | AC | 81 ms
16,824 KB |
testcase_85 | AC | 40 ms
11,460 KB |
testcase_86 | AC | 67 ms
15,128 KB |
testcase_87 | AC | 71 ms
16,152 KB |
testcase_88 | AC | 9 ms
6,944 KB |
testcase_89 | AC | 82 ms
17,012 KB |
testcase_90 | AC | 49 ms
11,940 KB |
testcase_91 | AC | 35 ms
10,268 KB |
testcase_92 | AC | 18 ms
7,028 KB |
testcase_93 | AC | 66 ms
14,472 KB |
testcase_94 | AC | 55 ms
13,580 KB |
testcase_95 | AC | 58 ms
13,436 KB |
testcase_96 | AC | 76 ms
16,348 KB |
testcase_97 | AC | 28 ms
9,260 KB |
testcase_98 | AC | 78 ms
16,628 KB |
testcase_99 | AC | 43 ms
11,388 KB |
testcase_100 | AC | 81 ms
17,408 KB |
testcase_101 | AC | 15 ms
6,944 KB |
testcase_102 | AC | 8 ms
6,944 KB |
testcase_103 | AC | 16 ms
6,940 KB |
testcase_104 | AC | 24 ms
8,404 KB |
testcase_105 | AC | 60 ms
14,600 KB |
testcase_106 | AC | 32 ms
9,784 KB |
testcase_107 | AC | 78 ms
17,016 KB |
testcase_108 | AC | 79 ms
16,964 KB |
testcase_109 | AC | 58 ms
14,312 KB |
testcase_110 | AC | 54 ms
13,452 KB |
testcase_111 | AC | 62 ms
14,096 KB |
testcase_112 | AC | 22 ms
7,892 KB |
testcase_113 | AC | 54 ms
12,612 KB |
testcase_114 | AC | 29 ms
9,600 KB |
testcase_115 | AC | 10 ms
6,944 KB |
testcase_116 | AC | 38 ms
10,720 KB |
testcase_117 | AC | 22 ms
8,208 KB |
testcase_118 | AC | 77 ms
16,444 KB |
testcase_119 | AC | 40 ms
11,112 KB |
testcase_120 | AC | 75 ms
15,844 KB |
testcase_121 | AC | 19 ms
7,368 KB |
testcase_122 | AC | 34 ms
10,556 KB |
testcase_123 | AC | 2 ms
6,940 KB |
testcase_124 | AC | 110 ms
26,328 KB |
testcase_125 | AC | 104 ms
26,240 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(int N) { ord.resize(N, -1); low.resize(N, -1); G.resize(N, vector<int>()); k = 0; joint_or_not.resize(N, false); } 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); build(); } void build() { for (int v = 0; v < (int) G.size(); ++v) { if (ord[v] == -1) { dfs(v); } } } void add_edge(int u, int v) { G[u].push_back(v); G[v].push_back(u); } 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() { std::cin.tie(0)->sync_with_stdio(0); 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; }