結果

問題 No.1254 補強への架け橋
ユーザー yuto1115yuto1115
提出日時 2020-10-09 22:49:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 3,120 bytes
コンパイル時間 2,180 ms
コンパイル使用メモリ 218,032 KB
実行使用メモリ 33,912 KB
最終ジャッジ日時 2023-09-27 18:47:47
合計ジャッジ時間 14,463 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 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,376 KB
testcase_11 AC 2 ms
4,380 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 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,384 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 3 ms
4,376 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 3 ms
4,376 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 2 ms
4,380 KB
testcase_53 AC 2 ms
4,376 KB
testcase_54 AC 3 ms
4,376 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 2 ms
4,380 KB
testcase_57 AC 2 ms
4,376 KB
testcase_58 AC 2 ms
4,376 KB
testcase_59 AC 1 ms
4,376 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 3 ms
4,380 KB
testcase_62 AC 1 ms
4,376 KB
testcase_63 AC 11 ms
5,436 KB
testcase_64 AC 4 ms
4,376 KB
testcase_65 AC 8 ms
4,516 KB
testcase_66 AC 7 ms
4,608 KB
testcase_67 AC 3 ms
4,380 KB
testcase_68 AC 8 ms
4,380 KB
testcase_69 AC 10 ms
4,680 KB
testcase_70 AC 5 ms
4,376 KB
testcase_71 AC 4 ms
4,376 KB
testcase_72 AC 9 ms
4,792 KB
testcase_73 AC 4 ms
4,380 KB
testcase_74 AC 9 ms
4,552 KB
testcase_75 AC 7 ms
4,396 KB
testcase_76 AC 3 ms
4,380 KB
testcase_77 AC 6 ms
4,380 KB
testcase_78 AC 12 ms
5,164 KB
testcase_79 AC 11 ms
5,108 KB
testcase_80 AC 11 ms
4,804 KB
testcase_81 AC 11 ms
5,100 KB
testcase_82 AC 10 ms
4,836 KB
testcase_83 AC 168 ms
21,344 KB
testcase_84 AC 152 ms
20,496 KB
testcase_85 AC 90 ms
14,268 KB
testcase_86 AC 126 ms
18,836 KB
testcase_87 AC 145 ms
19,900 KB
testcase_88 AC 18 ms
6,008 KB
testcase_89 AC 158 ms
21,356 KB
testcase_90 AC 88 ms
14,656 KB
testcase_91 AC 68 ms
12,528 KB
testcase_92 AC 34 ms
8,132 KB
testcase_93 AC 126 ms
17,996 KB
testcase_94 AC 104 ms
16,748 KB
testcase_95 AC 106 ms
16,772 KB
testcase_96 AC 147 ms
20,428 KB
testcase_97 AC 56 ms
11,224 KB
testcase_98 AC 148 ms
20,644 KB
testcase_99 AC 78 ms
13,760 KB
testcase_100 AC 157 ms
21,760 KB
testcase_101 AC 28 ms
7,668 KB
testcase_102 AC 15 ms
5,584 KB
testcase_103 AC 33 ms
8,244 KB
testcase_104 AC 45 ms
10,184 KB
testcase_105 AC 124 ms
17,996 KB
testcase_106 AC 61 ms
11,832 KB
testcase_107 AC 163 ms
21,412 KB
testcase_108 AC 156 ms
20,704 KB
testcase_109 AC 125 ms
17,424 KB
testcase_110 AC 106 ms
16,540 KB
testcase_111 AC 119 ms
17,516 KB
testcase_112 AC 43 ms
9,332 KB
testcase_113 AC 101 ms
15,764 KB
testcase_114 AC 62 ms
11,600 KB
testcase_115 AC 19 ms
6,200 KB
testcase_116 AC 71 ms
12,852 KB
testcase_117 AC 45 ms
9,692 KB
testcase_118 AC 167 ms
20,280 KB
testcase_119 AC 75 ms
13,740 KB
testcase_120 AC 152 ms
19,900 KB
testcase_121 AC 36 ms
8,576 KB
testcase_122 AC 72 ms
12,872 KB
testcase_123 AC 1 ms
4,376 KB
testcase_124 AC 161 ms
33,912 KB
testcase_125 AC 161 ms
33,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

class lowlink {
    vvi G;
    vi ord, low;
    
    int dfs(int v, int p, int k) {
        ord[v] = low[v] = k++;
        bool flag = false;
        int cnt = 0;
        for (int u : G[v]) {
            if (ord[u] < 0) {
                cnt++;
                k = dfs(u, v, k);
                chmin(low[v], low[u]);
                flag |= p >= 0 and ord[v] <= low[u];
                if (ord[v] < low[u]) bridge.eb(v, u);
            } else if (u != p) {
                chmin(low[v], ord[u]);
            }
        }
        flag |= p < 0 and cnt > 1;
        if (flag) articulation.pb(v);
        return k;
    }
    
    void init() {
        ord.assign(G.size(), -1);
        low.assign(G.size(), -1);
        int k = 0;
        rep(i, G.size()) {
            if (ord[i] < 0) k = dfs(i, -1, k);
        }
    }

public:
    vi articulation;
    vp bridge;
    
    lowlink(vvi &G) : G(G) { init(); }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vvi G(n);
    map<P, int> mp;
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        mp[{a, b}] = i+1;
        G[a].pb(b);
        G[b].pb(a);
    }
    lowlink lk(G);
    for (auto p : lk.bridge) {
        if (mp.count(p)) mp.erase(p);
        swap(p.first, p.second);
        if (mp.count(p)) mp.erase(p);
    }
    cout << mp.size() << '\n';
    for (auto p : mp) {
        cout << p.second << ' ';
    }
    cout << endl;
}
0