結果

問題 No.1254 補強への架け橋
ユーザー fumofumofunifumofumofuni
提出日時 2020-10-09 22:39:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 253 ms / 2,000 ms
コード長 3,374 bytes
コンパイル時間 1,909 ms
コンパイル使用メモリ 193,532 KB
実行使用メモリ 34,800 KB
最終ジャッジ日時 2023-09-27 18:35:29
合計ジャッジ時間 15,435 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 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 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,384 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,380 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,376 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 3 ms
4,380 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 2 ms
4,380 KB
testcase_53 AC 3 ms
4,376 KB
testcase_54 AC 3 ms
4,380 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 2 ms
4,376 KB
testcase_59 AC 1 ms
4,380 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 2 ms
4,380 KB
testcase_62 AC 2 ms
4,376 KB
testcase_63 AC 17 ms
5,188 KB
testcase_64 AC 6 ms
4,376 KB
testcase_65 AC 11 ms
4,548 KB
testcase_66 AC 8 ms
4,380 KB
testcase_67 AC 4 ms
4,376 KB
testcase_68 AC 9 ms
4,380 KB
testcase_69 AC 13 ms
4,748 KB
testcase_70 AC 6 ms
4,380 KB
testcase_71 AC 4 ms
4,376 KB
testcase_72 AC 13 ms
4,680 KB
testcase_73 AC 5 ms
4,376 KB
testcase_74 AC 12 ms
4,704 KB
testcase_75 AC 9 ms
4,616 KB
testcase_76 AC 3 ms
4,380 KB
testcase_77 AC 8 ms
4,376 KB
testcase_78 AC 14 ms
5,128 KB
testcase_79 AC 15 ms
5,028 KB
testcase_80 AC 13 ms
4,852 KB
testcase_81 AC 15 ms
5,204 KB
testcase_82 AC 13 ms
4,908 KB
testcase_83 AC 222 ms
22,860 KB
testcase_84 AC 253 ms
22,144 KB
testcase_85 AC 129 ms
14,968 KB
testcase_86 AC 184 ms
19,740 KB
testcase_87 AC 194 ms
21,252 KB
testcase_88 AC 25 ms
6,164 KB
testcase_89 AC 223 ms
22,628 KB
testcase_90 AC 126 ms
15,732 KB
testcase_91 AC 95 ms
13,472 KB
testcase_92 AC 47 ms
8,320 KB
testcase_93 AC 176 ms
18,708 KB
testcase_94 AC 153 ms
17,404 KB
testcase_95 AC 148 ms
17,368 KB
testcase_96 AC 213 ms
21,716 KB
testcase_97 AC 80 ms
11,732 KB
testcase_98 AC 216 ms
21,820 KB
testcase_99 AC 119 ms
14,460 KB
testcase_100 AC 229 ms
23,148 KB
testcase_101 AC 41 ms
8,044 KB
testcase_102 AC 20 ms
5,728 KB
testcase_103 AC 48 ms
8,596 KB
testcase_104 AC 67 ms
10,240 KB
testcase_105 AC 168 ms
18,752 KB
testcase_106 AC 91 ms
12,424 KB
testcase_107 AC 220 ms
22,636 KB
testcase_108 AC 219 ms
22,536 KB
testcase_109 AC 170 ms
18,480 KB
testcase_110 AC 151 ms
17,244 KB
testcase_111 AC 165 ms
18,224 KB
testcase_112 AC 61 ms
10,020 KB
testcase_113 AC 153 ms
16,920 KB
testcase_114 AC 88 ms
12,360 KB
testcase_115 AC 29 ms
6,200 KB
testcase_116 AC 98 ms
13,532 KB
testcase_117 AC 61 ms
10,132 KB
testcase_118 AC 215 ms
21,592 KB
testcase_119 AC 111 ms
14,540 KB
testcase_120 AC 202 ms
20,772 KB
testcase_121 AC 52 ms
8,892 KB
testcase_122 AC 97 ms
13,540 KB
testcase_123 AC 1 ms
4,376 KB
testcase_124 AC 189 ms
34,800 KB
testcase_125 AC 202 ms
34,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={0,0,1,-1,1,1,-1,-1,0};
const ll dx[9]={1,-1,0,0,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct Edge {
    int to;
};
using Graph = vector<vector<Edge>>;
using P = pair<long long, 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;
    }
};

int main(){
    ll n;cin >> n;
    vector<pl> v(n);
    vector<vector<Edge>> g(n);
    map<pl,ll> mp;
    rep(i,n){
        cin >> v[i].fi >> v[i].se;
        if(v[i].fi>v[i].se)swap(v[i].fi,v[i].se);
        v[i].fi--;v[i].se--;
        mp[v[i]]=i+1;
        Edge a,b;
        a.to=v[i].fi;b.to=v[i].se;
        g[v[i].fi].pb(b);
        g[v[i].se].pb(a);
    } 
    LowLink lk(g);
    set<ll> ans;
    rep(i,n)ans.ins(i+1);
    for(auto p:lk.bridges){
        ans.erase(mp[p]);
        //cout << p.fi << " " << p.se <<endl;
    }
    cout << ans.size() <<endl;
    for(auto p:ans)cout << p <<" ";
    cout << endl;
}
0