結果
問題 | No.1254 補強への架け橋 |
ユーザー | 👑 emthrm |
提出日時 | 2020-10-09 22:15:37 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 262 ms / 2,000 ms |
コード長 | 3,402 bytes |
コンパイル時間 | 2,632 ms |
コンパイル使用メモリ | 226,192 KB |
実行使用メモリ | 38,496 KB |
最終ジャッジ日時 | 2024-07-20 12:12:19 |
合計ジャッジ時間 | 18,421 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,944 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,944 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 3 ms
6,944 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 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,944 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 2 ms
6,944 KB |
testcase_23 | AC | 2 ms
6,940 KB |
testcase_24 | AC | 2 ms
6,940 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,940 KB |
testcase_29 | AC | 2 ms
6,944 KB |
testcase_30 | AC | 2 ms
6,940 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 2 ms
6,940 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,944 KB |
testcase_40 | AC | 2 ms
6,940 KB |
testcase_41 | AC | 2 ms
6,940 KB |
testcase_42 | AC | 2 ms
6,944 KB |
testcase_43 | AC | 3 ms
6,940 KB |
testcase_44 | AC | 3 ms
6,944 KB |
testcase_45 | AC | 3 ms
6,940 KB |
testcase_46 | AC | 3 ms
6,944 KB |
testcase_47 | AC | 2 ms
6,940 KB |
testcase_48 | AC | 2 ms
6,940 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,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,940 KB |
testcase_58 | AC | 2 ms
6,944 KB |
testcase_59 | AC | 2 ms
6,944 KB |
testcase_60 | AC | 2 ms
6,940 KB |
testcase_61 | AC | 2 ms
6,940 KB |
testcase_62 | AC | 2 ms
6,944 KB |
testcase_63 | AC | 16 ms
6,940 KB |
testcase_64 | AC | 5 ms
6,940 KB |
testcase_65 | AC | 10 ms
6,940 KB |
testcase_66 | AC | 9 ms
6,944 KB |
testcase_67 | AC | 4 ms
6,940 KB |
testcase_68 | AC | 9 ms
6,944 KB |
testcase_69 | AC | 11 ms
6,944 KB |
testcase_70 | AC | 5 ms
6,944 KB |
testcase_71 | AC | 5 ms
6,944 KB |
testcase_72 | AC | 12 ms
6,944 KB |
testcase_73 | AC | 5 ms
6,940 KB |
testcase_74 | AC | 12 ms
6,944 KB |
testcase_75 | AC | 9 ms
6,944 KB |
testcase_76 | AC | 3 ms
6,944 KB |
testcase_77 | AC | 8 ms
6,944 KB |
testcase_78 | AC | 15 ms
6,940 KB |
testcase_79 | AC | 15 ms
6,944 KB |
testcase_80 | AC | 14 ms
6,940 KB |
testcase_81 | AC | 15 ms
6,940 KB |
testcase_82 | AC | 14 ms
6,944 KB |
testcase_83 | AC | 262 ms
28,132 KB |
testcase_84 | AC | 234 ms
27,476 KB |
testcase_85 | AC | 132 ms
18,176 KB |
testcase_86 | AC | 199 ms
24,284 KB |
testcase_87 | AC | 213 ms
26,108 KB |
testcase_88 | AC | 23 ms
6,940 KB |
testcase_89 | AC | 251 ms
27,816 KB |
testcase_90 | AC | 138 ms
18,816 KB |
testcase_91 | AC | 100 ms
15,872 KB |
testcase_92 | AC | 44 ms
9,984 KB |
testcase_93 | AC | 181 ms
23,512 KB |
testcase_94 | AC | 157 ms
21,788 KB |
testcase_95 | AC | 160 ms
21,472 KB |
testcase_96 | AC | 230 ms
26,664 KB |
testcase_97 | AC | 80 ms
14,196 KB |
testcase_98 | AC | 232 ms
27,036 KB |
testcase_99 | AC | 127 ms
17,632 KB |
testcase_100 | AC | 247 ms
28,564 KB |
testcase_101 | AC | 40 ms
9,344 KB |
testcase_102 | AC | 19 ms
6,944 KB |
testcase_103 | AC | 45 ms
9,984 KB |
testcase_104 | AC | 68 ms
12,508 KB |
testcase_105 | AC | 187 ms
23,544 KB |
testcase_106 | AC | 92 ms
15,104 KB |
testcase_107 | AC | 252 ms
27,968 KB |
testcase_108 | AC | 243 ms
27,520 KB |
testcase_109 | AC | 183 ms
23,268 KB |
testcase_110 | AC | 157 ms
21,444 KB |
testcase_111 | AC | 184 ms
22,632 KB |
testcase_112 | AC | 62 ms
11,776 KB |
testcase_113 | AC | 149 ms
20,252 KB |
testcase_114 | AC | 92 ms
14,792 KB |
testcase_115 | AC | 26 ms
7,424 KB |
testcase_116 | AC | 104 ms
16,256 KB |
testcase_117 | AC | 63 ms
12,288 KB |
testcase_118 | AC | 230 ms
26,524 KB |
testcase_119 | AC | 120 ms
17,468 KB |
testcase_120 | AC | 217 ms
25,820 KB |
testcase_121 | AC | 50 ms
10,752 KB |
testcase_122 | AC | 102 ms
16,128 KB |
testcase_123 | AC | 2 ms
6,944 KB |
testcase_124 | AC | 208 ms
38,272 KB |
testcase_125 | AC | 202 ms
38,496 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; }