結果
問題 | No.1254 補強への架け橋 |
ユーザー | 👑 emthrm |
提出日時 | 2020-10-09 22:15:37 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 267 ms / 2,000 ms |
コード長 | 3,402 bytes |
コンパイル時間 | 4,266 ms |
コンパイル使用メモリ | 222,160 KB |
実行使用メモリ | 38,092 KB |
最終ジャッジ日時 | 2023-09-27 17:49:05 |
合計ジャッジ時間 | 17,088 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 1 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 2 ms
4,376 KB |
testcase_08 | AC | 1 ms
4,380 KB |
testcase_09 | AC | 1 ms
4,380 KB |
testcase_10 | AC | 1 ms
4,380 KB |
testcase_11 | AC | 2 ms
4,376 KB |
testcase_12 | AC | 1 ms
4,376 KB |
testcase_13 | AC | 1 ms
4,376 KB |
testcase_14 | AC | 2 ms
4,376 KB |
testcase_15 | AC | 2 ms
4,376 KB |
testcase_16 | AC | 2 ms
4,376 KB |
testcase_17 | AC | 1 ms
4,376 KB |
testcase_18 | AC | 1 ms
4,380 KB |
testcase_19 | AC | 1 ms
4,376 KB |
testcase_20 | AC | 1 ms
4,376 KB |
testcase_21 | AC | 1 ms
4,376 KB |
testcase_22 | AC | 2 ms
4,380 KB |
testcase_23 | AC | 2 ms
4,380 KB |
testcase_24 | AC | 1 ms
4,376 KB |
testcase_25 | AC | 1 ms
4,380 KB |
testcase_26 | AC | 2 ms
4,376 KB |
testcase_27 | AC | 2 ms
4,380 KB |
testcase_28 | AC | 1 ms
4,380 KB |
testcase_29 | AC | 2 ms
4,376 KB |
testcase_30 | AC | 2 ms
4,380 KB |
testcase_31 | AC | 1 ms
4,380 KB |
testcase_32 | AC | 2 ms
4,380 KB |
testcase_33 | AC | 2 ms
4,376 KB |
testcase_34 | AC | 2 ms
4,380 KB |
testcase_35 | AC | 2 ms
4,380 KB |
testcase_36 | AC | 2 ms
4,376 KB |
testcase_37 | AC | 1 ms
4,384 KB |
testcase_38 | AC | 1 ms
4,376 KB |
testcase_39 | AC | 1 ms
4,376 KB |
testcase_40 | AC | 2 ms
4,376 KB |
testcase_41 | AC | 1 ms
4,376 KB |
testcase_42 | AC | 2 ms
4,376 KB |
testcase_43 | AC | 3 ms
4,380 KB |
testcase_44 | AC | 2 ms
4,380 KB |
testcase_45 | AC | 2 ms
4,380 KB |
testcase_46 | AC | 2 ms
4,380 KB |
testcase_47 | AC | 2 ms
4,380 KB |
testcase_48 | AC | 2 ms
4,376 KB |
testcase_49 | AC | 2 ms
4,380 KB |
testcase_50 | AC | 3 ms
4,376 KB |
testcase_51 | AC | 2 ms
4,376 KB |
testcase_52 | AC | 3 ms
4,376 KB |
testcase_53 | AC | 2 ms
4,376 KB |
testcase_54 | AC | 3 ms
4,376 KB |
testcase_55 | AC | 3 ms
4,376 KB |
testcase_56 | AC | 2 ms
4,380 KB |
testcase_57 | AC | 2 ms
4,376 KB |
testcase_58 | AC | 2 ms
4,376 KB |
testcase_59 | AC | 2 ms
4,380 KB |
testcase_60 | AC | 2 ms
4,376 KB |
testcase_61 | AC | 3 ms
4,376 KB |
testcase_62 | AC | 2 ms
4,376 KB |
testcase_63 | AC | 15 ms
6,140 KB |
testcase_64 | AC | 5 ms
4,376 KB |
testcase_65 | AC | 10 ms
5,008 KB |
testcase_66 | AC | 9 ms
4,856 KB |
testcase_67 | AC | 4 ms
4,376 KB |
testcase_68 | AC | 8 ms
4,776 KB |
testcase_69 | AC | 11 ms
5,180 KB |
testcase_70 | AC | 5 ms
4,376 KB |
testcase_71 | AC | 4 ms
4,380 KB |
testcase_72 | AC | 12 ms
5,236 KB |
testcase_73 | AC | 5 ms
4,380 KB |
testcase_74 | AC | 11 ms
5,052 KB |
testcase_75 | AC | 8 ms
4,832 KB |
testcase_76 | AC | 3 ms
4,380 KB |
testcase_77 | AC | 8 ms
4,804 KB |
testcase_78 | AC | 15 ms
5,664 KB |
testcase_79 | AC | 15 ms
5,748 KB |
testcase_80 | AC | 12 ms
5,284 KB |
testcase_81 | AC | 14 ms
5,780 KB |
testcase_82 | AC | 13 ms
5,468 KB |
testcase_83 | AC | 248 ms
28,108 KB |
testcase_84 | AC | 250 ms
27,352 KB |
testcase_85 | AC | 126 ms
18,028 KB |
testcase_86 | AC | 198 ms
24,260 KB |
testcase_87 | AC | 231 ms
25,876 KB |
testcase_88 | AC | 23 ms
6,908 KB |
testcase_89 | AC | 246 ms
27,816 KB |
testcase_90 | AC | 141 ms
18,880 KB |
testcase_91 | AC | 101 ms
15,752 KB |
testcase_92 | AC | 46 ms
10,004 KB |
testcase_93 | AC | 191 ms
23,580 KB |
testcase_94 | AC | 164 ms
21,644 KB |
testcase_95 | AC | 160 ms
21,332 KB |
testcase_96 | AC | 243 ms
26,508 KB |
testcase_97 | AC | 82 ms
14,236 KB |
testcase_98 | AC | 248 ms
26,900 KB |
testcase_99 | AC | 127 ms
17,632 KB |
testcase_100 | AC | 267 ms
28,424 KB |
testcase_101 | AC | 39 ms
9,312 KB |
testcase_102 | AC | 20 ms
6,672 KB |
testcase_103 | AC | 44 ms
9,836 KB |
testcase_104 | AC | 67 ms
12,648 KB |
testcase_105 | AC | 196 ms
23,520 KB |
testcase_106 | AC | 95 ms
15,056 KB |
testcase_107 | AC | 250 ms
27,916 KB |
testcase_108 | AC | 248 ms
27,632 KB |
testcase_109 | AC | 186 ms
23,328 KB |
testcase_110 | AC | 163 ms
21,548 KB |
testcase_111 | AC | 170 ms
22,684 KB |
testcase_112 | AC | 65 ms
11,804 KB |
testcase_113 | AC | 178 ms
20,080 KB |
testcase_114 | AC | 86 ms
14,644 KB |
testcase_115 | AC | 25 ms
7,332 KB |
testcase_116 | AC | 105 ms
16,332 KB |
testcase_117 | AC | 64 ms
12,344 KB |
testcase_118 | AC | 239 ms
26,568 KB |
testcase_119 | AC | 118 ms
17,460 KB |
testcase_120 | AC | 226 ms
25,652 KB |
testcase_121 | AC | 51 ms
10,648 KB |
testcase_122 | AC | 102 ms
15,984 KB |
testcase_123 | AC | 2 ms
4,376 KB |
testcase_124 | AC | 210 ms
38,092 KB |
testcase_125 | AC | 208 ms
38,028 KB |
ソースコード
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 1000000007; // constexpr int MOD = 998244353; constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); } } iosetup; template <typename CostType> struct Edge { int src, dst; CostType cost; Edge(int src, int dst, CostType cost = 0) : src(src), dst(dst), cost(cost) {} inline bool operator<(const Edge &x) const { return cost != x.cost ? cost < x.cost : dst != x.dst ? dst < x.dst : src < x.src; } inline bool operator<=(const Edge &x) const { return !(x < *this); } inline bool operator>(const Edge &x) const { return x < *this; } inline bool operator>=(const Edge &x) const { return !(*this < x); } }; template <typename CostType> struct Lowlink { using E = Edge<CostType>; std::vector<std::vector<E>> graph; std::vector<int> ap; std::vector<E> bridge; Lowlink(const std::vector<std::vector<E>> &graph) : graph(graph) { int n = graph.size(); order.assign(n, -1); lowlink.resize(n); int tm = 0; for (int i = 0; i < n; ++i) { if (order[i] == -1) dfs(-1, i, tm); } // std::sort(ap.begin(), ap.end()); // std::sort(bridge.begin(), bridge.end(), [](const E &a, const E &b) -> bool { // return a.src != b.src ? a.src < b.src : a.dst != b.dst ? a.dst < b.dst : a.cost < b.cost; // }); } std::vector<int> order, lowlink; private: void dfs(int par, int ver, int &tm) { order[ver] = lowlink[ver] = tm++; int cnt = 0; bool is_ap = false; for (const E &e : graph[ver]) { if (order[e.dst] == -1) { ++cnt; dfs(ver, e.dst, tm); if (lowlink[e.dst] < lowlink[ver]) lowlink[ver] = lowlink[e.dst]; if (order[ver] <= lowlink[e.dst]) { is_ap = true; if (order[ver] < lowlink[e.dst]) bridge.emplace_back(std::min(ver, e.dst), std::max(ver, e.dst), e.cost); } } else if (e.dst != par) { if (order[e.dst] < lowlink[ver]) lowlink[ver] = order[e.dst]; } } if (par == -1) { if (cnt >= 2) ap.emplace_back(ver); } else { if (is_ap) ap.emplace_back(ver); } } }; int main() { int n; cin >> n; vector<vector<Edge<bool>>> graph(n); map<pair<int, int>, int> mp; REP(i, n) { int a, b; cin >> a >> b; --a; --b; if (a > b) swap(a, b); mp[{a, b}] = i; graph[a].emplace_back(a, b); graph[b].emplace_back(b, a); } set<int> st; REP(i, n) st.emplace(i); for (auto &e : Lowlink(graph).bridge) { int p = e.src, q = e.dst; if (p > q) swap(p, q); st.erase(mp[{p, q}]); } vector<int> ans(st.begin(), st.end()); int k = ans.size(); cout << k << '\n'; REP(i, k) cout << ans[i] + 1 << " \n"[i + 1 == k]; return 0; }