結果
問題 | No.1254 補強への架け橋 |
ユーザー | kyo1 |
提出日時 | 2020-11-11 04:03:48 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 351 ms / 2,000 ms |
コード長 | 2,692 bytes |
コンパイル時間 | 2,821 ms |
コンパイル使用メモリ | 235,412 KB |
実行使用メモリ | 54,272 KB |
最終ジャッジ日時 | 2024-07-22 18:17:50 |
合計ジャッジ時間 | 22,006 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,812 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 3 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 3 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | AC | 2 ms
6,944 KB |
testcase_18 | AC | 2 ms
6,944 KB |
testcase_19 | AC | 2 ms
6,944 KB |
testcase_20 | AC | 2 ms
6,944 KB |
testcase_21 | AC | 2 ms
6,944 KB |
testcase_22 | AC | 2 ms
6,944 KB |
testcase_23 | AC | 2 ms
6,944 KB |
testcase_24 | AC | 2 ms
6,940 KB |
testcase_25 | AC | 2 ms
6,940 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,944 KB |
testcase_30 | AC | 2 ms
6,944 KB |
testcase_31 | AC | 2 ms
6,944 KB |
testcase_32 | AC | 2 ms
6,944 KB |
testcase_33 | AC | 2 ms
6,940 KB |
testcase_34 | AC | 2 ms
6,944 KB |
testcase_35 | AC | 2 ms
6,940 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,940 KB |
testcase_40 | AC | 2 ms
6,940 KB |
testcase_41 | AC | 2 ms
6,944 KB |
testcase_42 | AC | 2 ms
6,944 KB |
testcase_43 | AC | 3 ms
6,940 KB |
testcase_44 | AC | 3 ms
6,940 KB |
testcase_45 | AC | 3 ms
6,944 KB |
testcase_46 | AC | 4 ms
6,940 KB |
testcase_47 | AC | 3 ms
6,940 KB |
testcase_48 | AC | 3 ms
6,944 KB |
testcase_49 | AC | 2 ms
6,940 KB |
testcase_50 | AC | 3 ms
6,940 KB |
testcase_51 | AC | 3 ms
6,940 KB |
testcase_52 | AC | 3 ms
6,940 KB |
testcase_53 | AC | 3 ms
6,944 KB |
testcase_54 | AC | 3 ms
6,944 KB |
testcase_55 | AC | 3 ms
6,940 KB |
testcase_56 | AC | 2 ms
6,940 KB |
testcase_57 | AC | 3 ms
6,944 KB |
testcase_58 | AC | 3 ms
6,940 KB |
testcase_59 | AC | 2 ms
6,944 KB |
testcase_60 | AC | 2 ms
6,944 KB |
testcase_61 | AC | 3 ms
6,944 KB |
testcase_62 | AC | 2 ms
6,944 KB |
testcase_63 | AC | 21 ms
6,944 KB |
testcase_64 | AC | 6 ms
6,940 KB |
testcase_65 | AC | 13 ms
6,944 KB |
testcase_66 | AC | 13 ms
6,940 KB |
testcase_67 | AC | 5 ms
6,944 KB |
testcase_68 | AC | 12 ms
6,940 KB |
testcase_69 | AC | 15 ms
6,940 KB |
testcase_70 | AC | 7 ms
6,944 KB |
testcase_71 | AC | 6 ms
6,944 KB |
testcase_72 | AC | 16 ms
6,944 KB |
testcase_73 | AC | 7 ms
6,944 KB |
testcase_74 | AC | 14 ms
6,940 KB |
testcase_75 | AC | 12 ms
6,940 KB |
testcase_76 | AC | 4 ms
6,944 KB |
testcase_77 | AC | 12 ms
6,940 KB |
testcase_78 | AC | 19 ms
6,944 KB |
testcase_79 | AC | 18 ms
6,940 KB |
testcase_80 | AC | 16 ms
6,944 KB |
testcase_81 | AC | 19 ms
6,940 KB |
testcase_82 | AC | 18 ms
6,940 KB |
testcase_83 | AC | 339 ms
36,776 KB |
testcase_84 | AC | 337 ms
35,856 KB |
testcase_85 | AC | 179 ms
23,796 KB |
testcase_86 | AC | 274 ms
31,680 KB |
testcase_87 | AC | 308 ms
34,128 KB |
testcase_88 | AC | 29 ms
8,320 KB |
testcase_89 | AC | 334 ms
36,664 KB |
testcase_90 | AC | 187 ms
24,920 KB |
testcase_91 | AC | 138 ms
20,404 KB |
testcase_92 | AC | 64 ms
12,288 KB |
testcase_93 | AC | 250 ms
30,048 KB |
testcase_94 | AC | 232 ms
27,712 KB |
testcase_95 | AC | 227 ms
27,636 KB |
testcase_96 | AC | 321 ms
35,020 KB |
testcase_97 | AC | 118 ms
17,960 KB |
testcase_98 | AC | 327 ms
35,280 KB |
testcase_99 | AC | 177 ms
22,796 KB |
testcase_100 | AC | 351 ms
37,560 KB |
testcase_101 | AC | 57 ms
11,392 KB |
testcase_102 | AC | 26 ms
7,552 KB |
testcase_103 | AC | 62 ms
12,160 KB |
testcase_104 | AC | 96 ms
15,676 KB |
testcase_105 | AC | 255 ms
30,160 KB |
testcase_106 | AC | 130 ms
19,232 KB |
testcase_107 | AC | 343 ms
36,696 KB |
testcase_108 | AC | 339 ms
36,188 KB |
testcase_109 | AC | 253 ms
29,684 KB |
testcase_110 | AC | 221 ms
27,192 KB |
testcase_111 | AC | 241 ms
28,992 KB |
testcase_112 | AC | 88 ms
14,976 KB |
testcase_113 | AC | 211 ms
26,688 KB |
testcase_114 | AC | 124 ms
18,640 KB |
testcase_115 | AC | 37 ms
8,832 KB |
testcase_116 | AC | 138 ms
21,148 KB |
testcase_117 | AC | 86 ms
15,096 KB |
testcase_118 | AC | 320 ms
34,564 KB |
testcase_119 | AC | 172 ms
22,684 KB |
testcase_120 | AC | 308 ms
33,720 KB |
testcase_121 | AC | 73 ms
13,312 KB |
testcase_122 | AC | 155 ms
20,800 KB |
testcase_123 | AC | 2 ms
5,376 KB |
testcase_124 | AC | 317 ms
54,272 KB |
testcase_125 | AC | 304 ms
54,272 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; template <typename T> class Edge { public: std::size_t from; std::size_t to; T cost; Edge(const std::size_t from, const std::size_t to, const T cost = 0) : from(from), to(to), cost(cost){}; bool operator<(const Edge<T> &rhs) const { return cost < rhs.cost; } bool operator>(const Edge<T> &rhs) const { return cost > rhs.cost; } }; template <typename T> class Graph { private: std::vector<std::vector<Edge<T>>> graph; public: explicit Graph(const std::size_t n) : graph(n) {} std::vector<Edge<T>> operator[](const std::size_t i) const { return graph[i]; } std::vector<Edge<T>> &operator[](const std::size_t i) { return graph[i]; } std::size_t size() const { return graph.size(); } void add(const std::size_t u, const std::size_t v, const T c = 0) { graph[u].emplace_back(Edge(u, v, c)); } }; template <typename T> class LowLink { public: const Graph<T> graph; std::vector<bool> used; std::vector<int> ord, low; std::vector<int> aps; std::vector<std::pair<int, int>> bridges; explicit LowLink(const Graph<T> &g) : graph(g), used(g.size(), false), ord(g.size(), 0), low(g.size(), 0) { int k = 0; for (int i = 0; i < (int)g.size(); i++) { if (!used[i]) k = dfs(i, k, -1); } sort(aps.begin(), aps.end()); sort(bridges.begin(), bridges.end()); } int dfs(int id, int k, int par) { used[id] = true; ord[id] = k++; low[id] = ord[id]; bool is_aps = false; int count = 0; for (auto &e : graph[id]) { if (!used[e.to]) { count++; k = dfs(e.to, k, id); low[id] = min(low[id], low[e.to]); if (par != -1 && ord[id] <= low[e.to]) is_aps = true; if (ord[id] < low[e.to]) bridges.emplace_back(make_pair(min(id, (int)e.to), max(id, (int)e.to))); } else if (e.to != par) { low[id] = min(low[id], ord[e.to]); } } if (par == -1 && count >= 2) is_aps = true; if (is_aps) aps.emplace_back(id); return k; }; }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; Graph<int> G(N); map<pair<int, int>, int> mp; for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; a--, b--; G.add(a, b); G.add(b, a); mp[make_pair(a, b)] = i; mp[make_pair(b, a)] = i; } LowLink ll(G); set<int> st; for (auto b : ll.bridges) { st.insert(mp[b]); } cout << N - st.size() << '\n'; vector<int> res; for (int i = 0; i < N; i++) { if (st.find(i) == st.end()) res.emplace_back(i); } for (const auto &e : res) { cout << e + 1 << (&e == &res.back() ? '\n' : ' '); } return 0; }