結果

問題 No.1254 補強への架け橋
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-10-10 01:45:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 352 ms / 2,000 ms
コード長 2,017 bytes
コンパイル時間 1,975 ms
コンパイル使用メモリ 185,344 KB
実行使用メモリ 27,692 KB
最終ジャッジ日時 2023-09-27 20:50:56
合計ジャッジ時間 18,767 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 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 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 3 ms
4,384 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 3 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 3 ms
4,380 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 3 ms
4,376 KB
testcase_51 AC 3 ms
4,376 KB
testcase_52 AC 3 ms
4,376 KB
testcase_53 AC 3 ms
4,380 KB
testcase_54 AC 3 ms
4,380 KB
testcase_55 AC 3 ms
4,380 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 2 ms
4,376 KB
testcase_58 AC 2 ms
4,380 KB
testcase_59 AC 2 ms
4,376 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 19 ms
5,128 KB
testcase_64 AC 5 ms
4,380 KB
testcase_65 AC 12 ms
4,504 KB
testcase_66 AC 10 ms
4,584 KB
testcase_67 AC 4 ms
4,376 KB
testcase_68 AC 11 ms
4,384 KB
testcase_69 AC 13 ms
4,808 KB
testcase_70 AC 7 ms
4,504 KB
testcase_71 AC 5 ms
4,384 KB
testcase_72 AC 14 ms
4,808 KB
testcase_73 AC 6 ms
4,380 KB
testcase_74 AC 13 ms
4,696 KB
testcase_75 AC 11 ms
4,424 KB
testcase_76 AC 4 ms
4,376 KB
testcase_77 AC 9 ms
4,376 KB
testcase_78 AC 17 ms
5,148 KB
testcase_79 AC 17 ms
5,040 KB
testcase_80 AC 15 ms
4,888 KB
testcase_81 AC 18 ms
5,104 KB
testcase_82 AC 16 ms
4,916 KB
testcase_83 AC 341 ms
22,944 KB
testcase_84 AC 331 ms
22,056 KB
testcase_85 AC 172 ms
15,180 KB
testcase_86 AC 264 ms
19,712 KB
testcase_87 AC 297 ms
21,028 KB
testcase_88 AC 28 ms
5,912 KB
testcase_89 AC 347 ms
22,796 KB
testcase_90 AC 183 ms
15,724 KB
testcase_91 AC 137 ms
13,340 KB
testcase_92 AC 56 ms
8,580 KB
testcase_93 AC 248 ms
18,840 KB
testcase_94 AC 219 ms
17,444 KB
testcase_95 AC 216 ms
17,276 KB
testcase_96 AC 325 ms
21,752 KB
testcase_97 AC 107 ms
11,560 KB
testcase_98 AC 326 ms
22,036 KB
testcase_99 AC 163 ms
14,700 KB
testcase_100 AC 352 ms
23,160 KB
testcase_101 AC 50 ms
7,848 KB
testcase_102 AC 23 ms
5,784 KB
testcase_103 AC 54 ms
8,528 KB
testcase_104 AC 89 ms
10,396 KB
testcase_105 AC 261 ms
19,012 KB
testcase_106 AC 118 ms
12,304 KB
testcase_107 AC 335 ms
22,856 KB
testcase_108 AC 333 ms
22,384 KB
testcase_109 AC 254 ms
18,588 KB
testcase_110 AC 217 ms
17,104 KB
testcase_111 AC 225 ms
18,148 KB
testcase_112 AC 77 ms
9,984 KB
testcase_113 AC 194 ms
16,592 KB
testcase_114 AC 115 ms
12,104 KB
testcase_115 AC 31 ms
6,472 KB
testcase_116 AC 134 ms
13,368 KB
testcase_117 AC 77 ms
10,060 KB
testcase_118 AC 314 ms
21,488 KB
testcase_119 AC 150 ms
14,468 KB
testcase_120 AC 294 ms
20,972 KB
testcase_121 AC 60 ms
8,764 KB
testcase_122 AC 130 ms
13,224 KB
testcase_123 AC 2 ms
4,380 KB
testcase_124 AC 249 ms
27,692 KB
testcase_125 AC 257 ms
27,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.10.10 01:45:40
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;


struct LowLink {
private:
    vector< vector< int > > G;
    int V; 
    vector< int > used, ord, low;
    int dfs(int idx, int k, int par) {
        used[idx] = true;
        ord[idx] = k++;
        low[idx] = ord[idx];
        bool is_articulation = false;
        int cnt = 0;
        for (auto &to : G[idx]) {
            if (!used[to]) {
                ++cnt;
                k = dfs(to, k, idx);
                low[idx] = min(low[idx], low[to]);
                is_articulation |= ~par && low[to] >= ord[idx];
                if (ord[idx] < low[to]) bridge.push_back(minmax(idx, (int)to));
            }
            else if (to != par) {
                low[idx] = min(low[idx], ord[to]);
            }
        }
        is_articulation |= par == -1 && cnt > 1;
        if (is_articulation) articulation.push_back(idx);
        return k;
    }
public:
    vector< int > articulation; 
    vector< pair< int, int > > bridge; 
    LowLink(int V) : V(V) {
        G.resize(V);
    }
    
    void add_edge(int v, int u) {
        G[v].push_back(u);
        G[u].push_back(v);
    }
    void build() {
        used.assign(V, 0);
        ord.assign(V, 0);
        low.assign(V, 0);
        int k = 0;
        for (int i = 0; i < V; i++) {
            if (!used[i]) k = dfs(i, k, -1);
        }
    }
};
int main() {
    int n;cin >> n;
    LowLink g(n);
    vector<pair<int,int>> edge(n);
    map<pair<int,int>,int> mp;
    for (int i = 0; i < n; i++) {
        int a,b;cin >> a >> b;
        a--;b--;
        edge[i] = {a,b};
        mp[{a,b}] = i+1;
        g.add_edge(a,b);
    }
    g.build();
    cout << n - g.bridge.size() << endl;
    for (auto p : g.bridge) {
        mp[p] = -1;
        mp[{p.second,p.first}] = -1;
    }
    for (int i = 0; i < n; i++) {
        if (mp[edge[i]] != -1) cout << i+1 << " ";
    }
    cout << endl;
    return 0;
}
0