結果

問題 No.1254 補強への架け橋
ユーザー firiexpfiriexp
提出日時 2020-10-09 21:33:39
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 2,488 bytes
コンパイル時間 1,213 ms
コンパイル使用メモリ 111,612 KB
実行使用メモリ 18,144 KB
最終ジャッジ日時 2023-09-27 15:00:26
合計ジャッジ時間 11,796 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 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,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 2 ms
4,376 KB
testcase_53 AC 2 ms
4,376 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 2 ms
4,376 KB
testcase_58 AC 2 ms
4,376 KB
testcase_59 AC 2 ms
4,376 KB
testcase_60 AC 2 ms
4,380 KB
testcase_61 AC 1 ms
4,380 KB
testcase_62 AC 1 ms
4,380 KB
testcase_63 AC 6 ms
4,700 KB
testcase_64 AC 3 ms
4,376 KB
testcase_65 AC 5 ms
4,376 KB
testcase_66 AC 4 ms
4,376 KB
testcase_67 AC 2 ms
4,376 KB
testcase_68 AC 4 ms
4,376 KB
testcase_69 AC 5 ms
4,376 KB
testcase_70 AC 4 ms
4,380 KB
testcase_71 AC 3 ms
4,376 KB
testcase_72 AC 5 ms
4,380 KB
testcase_73 AC 2 ms
4,376 KB
testcase_74 AC 5 ms
4,380 KB
testcase_75 AC 4 ms
4,380 KB
testcase_76 AC 2 ms
4,376 KB
testcase_77 AC 4 ms
4,376 KB
testcase_78 AC 5 ms
4,476 KB
testcase_79 AC 7 ms
4,508 KB
testcase_80 AC 5 ms
4,376 KB
testcase_81 AC 6 ms
4,488 KB
testcase_82 AC 6 ms
4,380 KB
testcase_83 AC 61 ms
16,100 KB
testcase_84 AC 58 ms
15,812 KB
testcase_85 AC 34 ms
11,168 KB
testcase_86 AC 48 ms
15,568 KB
testcase_87 AC 53 ms
16,652 KB
testcase_88 AC 9 ms
5,376 KB
testcase_89 AC 60 ms
16,160 KB
testcase_90 AC 39 ms
11,348 KB
testcase_91 AC 30 ms
9,792 KB
testcase_92 AC 15 ms
6,576 KB
testcase_93 AC 47 ms
14,436 KB
testcase_94 AC 45 ms
13,848 KB
testcase_95 AC 42 ms
13,868 KB
testcase_96 AC 55 ms
15,620 KB
testcase_97 AC 26 ms
9,016 KB
testcase_98 AC 58 ms
15,744 KB
testcase_99 AC 33 ms
10,648 KB
testcase_100 AC 62 ms
16,628 KB
testcase_101 AC 14 ms
6,376 KB
testcase_102 AC 8 ms
4,792 KB
testcase_103 AC 16 ms
6,552 KB
testcase_104 AC 21 ms
8,572 KB
testcase_105 AC 48 ms
15,420 KB
testcase_106 AC 26 ms
9,404 KB
testcase_107 AC 62 ms
15,920 KB
testcase_108 AC 58 ms
15,900 KB
testcase_109 AC 46 ms
14,612 KB
testcase_110 AC 40 ms
13,692 KB
testcase_111 AC 42 ms
14,252 KB
testcase_112 AC 21 ms
7,700 KB
testcase_113 AC 39 ms
12,088 KB
testcase_114 AC 26 ms
9,388 KB
testcase_115 AC 9 ms
5,244 KB
testcase_116 AC 29 ms
10,080 KB
testcase_117 AC 21 ms
8,468 KB
testcase_118 AC 55 ms
15,716 KB
testcase_119 AC 31 ms
10,604 KB
testcase_120 AC 54 ms
15,508 KB
testcase_121 AC 17 ms
6,980 KB
testcase_122 AC 28 ms
9,892 KB
testcase_123 AC 2 ms
4,376 KB
testcase_124 AC 69 ms
18,136 KB
testcase_125 AC 68 ms
18,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

class TwoEdgeConnectedComponents {
    void dfs(int i, int &pos){
        ord[i] = low[i] = pos++;
        int mul = 0;
        for (auto &&j : G[i]) {
            if(j == par[i] && !mul){
                mul = 1;
                continue;
            }
            if(~ord[j]){
                low[i] = min(low[i], ord[j]);
                continue;
            }
            par[j] = i;
            dfs(j, pos);
            size[i] += size[j];
            low[i] = min(low[i], low[j]);
        }
    }

    void dfs2(int i){
        out[bridge[i]].emplace_back(i);
        for (auto &&j : G[i]) {
            if(~bridge[j] || is_bridge(i, j)) continue;
            bridge[j] = bridge[i];
            dfs2(j);
        }
    }
public:
    vector<int> ord, low, par, bridge, size;
    vector<vector<int>> G, out;
    explicit TwoEdgeConnectedComponents(int n): ord(n, -1), low(n), par(n, -1), bridge(n, -1), size(n, 1), G(n){}

    inline bool is_bridge(int i, int j){
        if(ord[i] > ord[j]) swap(i, j);
        return ord[i] < low[j];
    }

    void add_edge(int u, int v){
        if(u != v){
            G[u].emplace_back(v);
            G[v].emplace_back(u);
        }
    }

    int build(){
        int n = G.size(), pos = 0;
        for (int i = 0; i < n; ++i) {
            if(ord[i] < 0) dfs(i, pos);
        }
        int k = 0;
        for (int i = 0; i < n; ++i) {
            if(!~bridge[i]){
                bridge[i] = k++;
                out.emplace_back();
                dfs2(i);
            }
        }
        return k;
    }
};

int main() {
    int n;
    cin >> n;
    TwoEdgeConnectedComponents G(n);
    vector<int> ans;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &a[i], &b[i]);
        a[i]--; b[i]--;
        G.add_edge(a[i], b[i]);
    }
    G.build();
    for (int i = 0; i < n; ++i) {
        if(!G.is_bridge(a[i], b[i])){
            ans.emplace_back(i+1);
        }
    }
    cout << ans.size() << "\n";
    for (int i = 0; i < ans.size(); ++i) {
        if(i) printf(" ");
        printf("%d", ans[i]);
    }
    puts("");
    return 0;
}
0