結果

問題 No.1254 補強への架け橋
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-12-23 18:06:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 2,282 bytes
コンパイル時間 2,607 ms
コンパイル使用メモリ 216,976 KB
実行使用メモリ 25,796 KB
最終ジャッジ日時 2023-12-23 18:06:27
合計ジャッジ時間 16,004 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 1 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 1 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 2 ms
6,676 KB
testcase_38 AC 2 ms
6,676 KB
testcase_39 AC 2 ms
6,676 KB
testcase_40 AC 2 ms
6,676 KB
testcase_41 AC 2 ms
6,676 KB
testcase_42 AC 2 ms
6,676 KB
testcase_43 AC 2 ms
6,676 KB
testcase_44 AC 2 ms
6,676 KB
testcase_45 AC 2 ms
6,676 KB
testcase_46 AC 2 ms
6,676 KB
testcase_47 AC 2 ms
6,676 KB
testcase_48 AC 2 ms
6,676 KB
testcase_49 AC 2 ms
6,676 KB
testcase_50 AC 2 ms
6,676 KB
testcase_51 AC 2 ms
6,676 KB
testcase_52 AC 2 ms
6,676 KB
testcase_53 AC 2 ms
6,676 KB
testcase_54 AC 2 ms
6,676 KB
testcase_55 AC 2 ms
6,676 KB
testcase_56 AC 2 ms
6,676 KB
testcase_57 AC 3 ms
6,676 KB
testcase_58 AC 2 ms
6,676 KB
testcase_59 AC 2 ms
6,676 KB
testcase_60 AC 2 ms
6,676 KB
testcase_61 AC 3 ms
6,676 KB
testcase_62 AC 2 ms
6,676 KB
testcase_63 AC 7 ms
6,676 KB
testcase_64 AC 3 ms
6,676 KB
testcase_65 AC 5 ms
6,676 KB
testcase_66 AC 5 ms
6,676 KB
testcase_67 AC 3 ms
6,676 KB
testcase_68 AC 4 ms
6,676 KB
testcase_69 AC 6 ms
6,676 KB
testcase_70 AC 4 ms
6,676 KB
testcase_71 AC 3 ms
6,676 KB
testcase_72 AC 6 ms
6,676 KB
testcase_73 AC 3 ms
6,676 KB
testcase_74 AC 5 ms
6,676 KB
testcase_75 AC 5 ms
6,676 KB
testcase_76 AC 3 ms
6,676 KB
testcase_77 AC 4 ms
6,676 KB
testcase_78 AC 6 ms
6,676 KB
testcase_79 AC 7 ms
6,676 KB
testcase_80 AC 6 ms
6,676 KB
testcase_81 AC 7 ms
6,676 KB
testcase_82 AC 6 ms
6,676 KB
testcase_83 AC 95 ms
17,520 KB
testcase_84 AC 88 ms
17,424 KB
testcase_85 AC 43 ms
11,364 KB
testcase_86 AC 71 ms
15,440 KB
testcase_87 AC 75 ms
16,668 KB
testcase_88 AC 10 ms
6,676 KB
testcase_89 AC 84 ms
17,324 KB
testcase_90 AC 45 ms
11,740 KB
testcase_91 AC 35 ms
10,108 KB
testcase_92 AC 18 ms
6,904 KB
testcase_93 AC 66 ms
15,104 KB
testcase_94 AC 56 ms
14,548 KB
testcase_95 AC 55 ms
14,532 KB
testcase_96 AC 74 ms
17,088 KB
testcase_97 AC 29 ms
9,532 KB
testcase_98 AC 81 ms
16,908 KB
testcase_99 AC 41 ms
11,064 KB
testcase_100 AC 83 ms
17,920 KB
testcase_101 AC 17 ms
6,676 KB
testcase_102 AC 9 ms
6,676 KB
testcase_103 AC 18 ms
6,876 KB
testcase_104 AC 24 ms
9,032 KB
testcase_105 AC 65 ms
15,112 KB
testcase_106 AC 31 ms
9,844 KB
testcase_107 AC 87 ms
17,328 KB
testcase_108 AC 83 ms
17,488 KB
testcase_109 AC 59 ms
15,032 KB
testcase_110 AC 54 ms
14,472 KB
testcase_111 AC 58 ms
14,856 KB
testcase_112 AC 22 ms
7,860 KB
testcase_113 AC 52 ms
12,400 KB
testcase_114 AC 32 ms
9,744 KB
testcase_115 AC 11 ms
6,676 KB
testcase_116 AC 38 ms
10,272 KB
testcase_117 AC 23 ms
8,904 KB
testcase_118 AC 79 ms
17,024 KB
testcase_119 AC 41 ms
10,864 KB
testcase_120 AC 80 ms
16,668 KB
testcase_121 AC 20 ms
7,232 KB
testcase_122 AC 39 ms
10,188 KB
testcase_123 AC 2 ms
6,676 KB
testcase_124 AC 107 ms
25,796 KB
testcase_125 AC 114 ms
25,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int N, A, B;
    cin >> N;
    vector<vector<pair<int, int>>> E(N);

    for (int i=0; i<N; i++){
        cin >> A >> B;
        A--; B--;
        E[A].push_back({B, i});
        E[B].push_back({A, i});
    }

    vector<int> in(N, -1), low(N), tour, ancestor(N);
    vector<bool> double_edge(N);
    auto lowlink=[&](auto self, int from, int p)->void{
        in[from] = tour.size();
        low[from] = tour.size();
        tour.push_back(from);
        ancestor[from] = p;
        for (auto [to, _] : E[from]){
            if (to == p){
                if (double_edge[from]) low[from] = min(low[from], in[to]);
                else double_edge[from]=1;
                continue;
            }
            if (in[to] != -1){
                if (in[to] > in[from]) continue;
                low[from] = min(low[from], in[to]); //後退辺(子孫->祖先)を遡る
            }
            else self(self, to, from);
        }
    };
    lowlink(lowlink, 0, -1);
    for (int i=N-1; i>=0; i--){
        int x = tour[i];
        for (auto [y, _] : E[x]){
            if (y == ancestor[x]) continue;
            low[x] = min(low[x], low[y]);
        }
    }

    //二重辺連結成分分解(two edge connected component)
    vector<vector<int>> tecc_groups;
    vector<int> _tecc, bridge, roots={0};
    vector<int> tecc_idx(N, -1); //頂点iの含まれる成分の番号
    auto tecc=[&](auto self, int from)->void{
        _tecc.push_back(from);
        tecc_idx[from] = tecc_groups.size();
        for (auto [to, idx] : E[from]){
            if (tecc_idx[to] != -1) continue;
            if (low[to] > in[from]){
                bridge.push_back(idx);
                roots.push_back(to);
            }
            else self(self, to);
        }
    };
    while(!roots.empty()){
        int root = roots.back();
        roots.pop_back();
        tecc(tecc, root);
        tecc_groups.push_back(_tecc);
        _tecc.clear();
    }

    vector<bool> ok(N, 1);
    for (auto x : bridge) ok[x] = 0;
    cout << N-bridge.size() << endl;
    for (int i=0; i<N; i++) if (ok[i]) cout << i+1 << " ";
    cout << endl;

    return 0;
}
0