結果
問題 | No.1254 補強への架け橋 |
ユーザー | iiljj |
提出日時 | 2020-10-09 22:49:51 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 256 ms / 2,000 ms |
コード長 | 8,900 bytes |
コンパイル時間 | 2,963 ms |
コンパイル使用メモリ | 234,764 KB |
実行使用メモリ | 40,660 KB |
最終ジャッジ日時 | 2024-07-20 13:17:45 |
合計ジャッジ時間 | 16,073 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 1 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 2 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 1 ms
5,376 KB |
testcase_28 | AC | 1 ms
5,376 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | AC | 2 ms
5,376 KB |
testcase_32 | AC | 2 ms
5,376 KB |
testcase_33 | AC | 1 ms
5,376 KB |
testcase_34 | AC | 2 ms
5,376 KB |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 2 ms
5,376 KB |
testcase_37 | AC | 1 ms
5,376 KB |
testcase_38 | AC | 2 ms
5,376 KB |
testcase_39 | AC | 2 ms
5,376 KB |
testcase_40 | AC | 1 ms
5,376 KB |
testcase_41 | AC | 2 ms
5,376 KB |
testcase_42 | AC | 2 ms
5,376 KB |
testcase_43 | AC | 2 ms
5,376 KB |
testcase_44 | AC | 2 ms
5,376 KB |
testcase_45 | AC | 2 ms
5,376 KB |
testcase_46 | AC | 2 ms
5,376 KB |
testcase_47 | AC | 2 ms
5,376 KB |
testcase_48 | AC | 3 ms
5,376 KB |
testcase_49 | AC | 2 ms
5,376 KB |
testcase_50 | AC | 3 ms
5,376 KB |
testcase_51 | AC | 3 ms
5,376 KB |
testcase_52 | AC | 2 ms
5,376 KB |
testcase_53 | AC | 2 ms
5,376 KB |
testcase_54 | AC | 3 ms
5,376 KB |
testcase_55 | AC | 2 ms
5,376 KB |
testcase_56 | AC | 2 ms
5,376 KB |
testcase_57 | AC | 2 ms
5,376 KB |
testcase_58 | AC | 2 ms
5,376 KB |
testcase_59 | AC | 2 ms
5,376 KB |
testcase_60 | AC | 2 ms
5,376 KB |
testcase_61 | AC | 2 ms
5,376 KB |
testcase_62 | AC | 2 ms
5,376 KB |
testcase_63 | AC | 16 ms
6,016 KB |
testcase_64 | AC | 5 ms
5,376 KB |
testcase_65 | AC | 11 ms
5,376 KB |
testcase_66 | AC | 8 ms
5,376 KB |
testcase_67 | AC | 4 ms
5,376 KB |
testcase_68 | AC | 9 ms
5,376 KB |
testcase_69 | AC | 13 ms
5,376 KB |
testcase_70 | AC | 6 ms
5,376 KB |
testcase_71 | AC | 5 ms
5,376 KB |
testcase_72 | AC | 12 ms
5,376 KB |
testcase_73 | AC | 5 ms
5,376 KB |
testcase_74 | AC | 12 ms
5,376 KB |
testcase_75 | AC | 9 ms
5,376 KB |
testcase_76 | AC | 3 ms
5,376 KB |
testcase_77 | AC | 8 ms
5,376 KB |
testcase_78 | AC | 15 ms
5,760 KB |
testcase_79 | AC | 15 ms
5,760 KB |
testcase_80 | AC | 13 ms
5,392 KB |
testcase_81 | AC | 16 ms
5,632 KB |
testcase_82 | AC | 14 ms
5,632 KB |
testcase_83 | AC | 235 ms
28,112 KB |
testcase_84 | AC | 256 ms
27,336 KB |
testcase_85 | AC | 123 ms
18,012 KB |
testcase_86 | AC | 192 ms
24,444 KB |
testcase_87 | AC | 231 ms
26,264 KB |
testcase_88 | AC | 24 ms
7,168 KB |
testcase_89 | AC | 239 ms
27,932 KB |
testcase_90 | AC | 144 ms
18,936 KB |
testcase_91 | AC | 97 ms
15,948 KB |
testcase_92 | AC | 48 ms
9,984 KB |
testcase_93 | AC | 178 ms
23,484 KB |
testcase_94 | AC | 165 ms
21,912 KB |
testcase_95 | AC | 156 ms
21,612 KB |
testcase_96 | AC | 220 ms
26,680 KB |
testcase_97 | AC | 84 ms
14,284 KB |
testcase_98 | AC | 239 ms
27,048 KB |
testcase_99 | AC | 120 ms
17,512 KB |
testcase_100 | AC | 244 ms
28,540 KB |
testcase_101 | AC | 42 ms
9,216 KB |
testcase_102 | AC | 22 ms
6,528 KB |
testcase_103 | AC | 45 ms
9,856 KB |
testcase_104 | AC | 65 ms
12,720 KB |
testcase_105 | AC | 177 ms
23,632 KB |
testcase_106 | AC | 90 ms
15,168 KB |
testcase_107 | AC | 250 ms
27,956 KB |
testcase_108 | AC | 230 ms
27,384 KB |
testcase_109 | AC | 176 ms
23,412 KB |
testcase_110 | AC | 158 ms
21,708 KB |
testcase_111 | AC | 171 ms
22,872 KB |
testcase_112 | AC | 62 ms
11,776 KB |
testcase_113 | AC | 142 ms
20,140 KB |
testcase_114 | AC | 86 ms
14,744 KB |
testcase_115 | AC | 26 ms
7,424 KB |
testcase_116 | AC | 109 ms
16,340 KB |
testcase_117 | AC | 62 ms
12,360 KB |
testcase_118 | AC | 225 ms
26,676 KB |
testcase_119 | AC | 116 ms
17,412 KB |
testcase_120 | AC | 214 ms
25,748 KB |
testcase_121 | AC | 52 ms
10,536 KB |
testcase_122 | AC | 102 ms
16,168 KB |
testcase_123 | AC | 2 ms
5,376 KB |
testcase_124 | AC | 211 ms
40,656 KB |
testcase_125 | AC | 224 ms
40,660 KB |
ソースコード
/* #region Head */ // #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pll = pair<ll, ll>; template <class T> using vc = vector<T>; template <class T> using vvc = vc<vc<T>>; using vll = vc<ll>; using vvll = vvc<ll>; using vld = vc<ld>; using vvld = vvc<ld>; using vs = vc<string>; using vvs = vvc<string>; template <class T, class U> using um = unordered_map<T, U>; template <class T> using pq = priority_queue<T>; template <class T> using pqa = priority_queue<T, vc<T>, greater<T>>; template <class T> using us = unordered_set<T>; #define REP(i, m, n) for (ll i = (m), i##_len = (ll)(n); i < i##_len; ++(i)) #define REPM(i, m, n) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; ++(i)) #define REPR(i, m, n) for (ll i = (m), i##_min = (ll)(n); i >= i##_min; --(i)) #define REPD(i, m, n, d) for (ll i = (m), i##_len = (ll)(n); i < i##_len; i += (d)) #define REPMD(i, m, n, d) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; i += (d)) #define REPI(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) #define ALL(x) begin(x), end(x) #define SIZE(x) ((ll)(x).size()) #define PERM(c) \ sort(ALL(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c))) #define UNIQ(v) v.erase(unique(ALL(v)), v.end()); #define endl '\n' #define sqrt sqrtl #define floor floorl #define log2 log2l constexpr ll INF = 1'010'000'000'000'000'017LL; constexpr int IINF = 1'000'000'007LL; constexpr ll MOD = 1'000'000'007LL; // 1e9 + 7 // constexpr ll MOD = 998244353; constexpr ld EPS = 1e-12; constexpr ld PI = 3.14159265358979323846; template <typename T> istream &operator>>(istream &is, vc<T> &vec) { // vector 入力 for (T &x : vec) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, vc<T> &vec) { // vector 出力 (for dump) os << "{"; REP(i, 0, SIZE(vec)) os << vec[i] << (i == i_len - 1 ? "" : ", "); os << "}"; return os; } template <typename T> ostream &operator>>(ostream &os, vc<T> &vec) { // vector 出力 (inline) REP(i, 0, SIZE(vec)) os << vec[i] << (i == i_len - 1 ? "\n" : " "); return os; } template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &pair_var) { // pair 入力 is >> pair_var.first >> pair_var.second; return is; } template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { // pair 出力 os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // map, um, set, us 出力 template <class T> ostream &out_iter(ostream &os, T &map_var) { os << "{"; REPI(itr, map_var) { os << *itr; auto itrcp = itr; if (++itrcp != map_var.end()) os << ", "; } return os << "}"; } template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { return out_iter(os, map_var); } template <typename T, typename U> ostream &operator<<(ostream &os, um<T, U> &map_var) { os << "{"; REPI(itr, map_var) { auto [key, value] = *itr; os << "(" << key << ", " << value << ")"; auto itrcp = itr; if (++itrcp != map_var.end()) os << ", "; } os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { return out_iter(os, set_var); } template <typename T> ostream &operator<<(ostream &os, us<T> &set_var) { return out_iter(os, set_var); } template <typename T> ostream &operator<<(ostream &os, pq<T> &pq_var) { pq<T> pq_cp(pq_var); os << "{"; if (!pq_cp.empty()) { os << pq_cp.top(), pq_cp.pop(); while (!pq_cp.empty()) os << ", " << pq_cp.top(), pq_cp.pop(); } return os << "}"; } // dump #define DUMPOUT cerr void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) DUMPOUT << ", "; dump_func(move(tail)...); } // chmax (更新「される」かもしれない値が前) template <typename T, typename U, typename Comp = less<>> bool chmax(T &xmax, const U &x, Comp comp = {}) { if (comp(xmax, x)) { xmax = x; return true; } return false; } // chmin (更新「される」かもしれない値が前) template <typename T, typename U, typename Comp = less<>> bool chmin(T &xmin, const U &x, Comp comp = {}) { if (comp(x, xmin)) { xmin = x; return true; } return false; } // ローカル用 #define DEBUG_ #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif #define VAR(type, ...) \ type __VA_ARGS__; \ cin >> __VA_ARGS__; template <typename T> istream &operator,(istream &is, T &rhs) { return is >> rhs; } template <typename T> ostream &operator,(ostream &os, const T &rhs) { return os << ' ' << rhs; } struct AtCoderInitialize { static constexpr int IOS_PREC = 15; static constexpr bool AUTOFLUSH = false; AtCoderInitialize() { ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); cout << fixed << setprecision(IOS_PREC); if (AUTOFLUSH) cout << unitbuf; } } ATCODER_INITIALIZE; void Yn(bool p) { cout << (p ? "Yes" : "No") << endl; } void YN(bool p) { cout << (p ? "YES" : "NO") << endl; } /* #endregion */ // #include <atcoder/all> // using namespace atcoder; struct Edge { int to; }; using Graph = vector<vector<Edge>>; using P = pair<long, long>; /* Lowlink: グラフの関節点・橋を列挙する構造体 作成: O(E+V) 関節点の集合: vector<int> aps 橋の集合: vector<P> bridges */ struct LowLink { const Graph &G; vector<int> used, ord, low; vector<int> aps; // articulation points vector<P> bridges; LowLink(const Graph &G_) : G(G_) { used.assign(G.size(), 0); ord.assign(G.size(), 0); low.assign(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) { // id:探索中の頂点, k:dfsで何番目に探索するか, par:idの親 used[id] = true; ord[id] = k++; low[id] = ord[id]; bool is_aps = false; int count = 0; // 子の数 for (auto &e : G[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(min(id, e.to), max(id, e.to)); // 条件を満たすので橋 } else if (e.to != par) { // eが後退辺の時 low[id] = min(low[id], ord[e.to]); } } if (par == -1 && count >= 2) is_aps = true; if (is_aps) aps.push_back(id); return k; } }; // Problem void solve() { // 取り去っても木が維持されるような辺を除去したい,そのような辺を探す // -> ループからは1個とっても大丈夫 VAR(ll, n); map<P, ll> edgenum; set<ll> edgenumset; Graph g(n); REP(i, 0, n) { VAR(int, a, b); --a, --b; P key0 = {a, b}; P key1 = {b, a}; edgenum[key0] = i + 1; edgenum[key1] = i + 1; g[a].push_back({b}); g[b].push_back({a}); edgenumset.insert(i + 1); } LowLink lnk(g); for (auto &bridge : lnk.bridges) { ll num = edgenum[bridge]; edgenumset.erase(num); } vll out; for (ll num : edgenumset) out.push_back(num); cout << SIZE(out) << endl; cout >> out; } // entry point int main() { solve(); return 0; }