結果

問題 No.1254 補強への架け橋
ユーザー raven7959raven7959
提出日時 2022-09-02 14:50:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 5,396 bytes
コンパイル時間 2,208 ms
コンパイル使用メモリ 218,448 KB
実行使用メモリ 21,432 KB
最終ジャッジ日時 2024-04-27 16:15:03
合計ジャッジ時間 12,669 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 1 ms
6,940 KB
testcase_33 AC 2 ms
6,944 KB
testcase_34 AC 2 ms
6,944 KB
testcase_35 AC 1 ms
6,944 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 2 ms
6,944 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 2 ms
6,940 KB
testcase_42 AC 1 ms
6,944 KB
testcase_43 AC 2 ms
6,940 KB
testcase_44 AC 2 ms
6,940 KB
testcase_45 AC 2 ms
6,944 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,944 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 1 ms
6,940 KB
testcase_50 AC 2 ms
6,940 KB
testcase_51 AC 2 ms
6,944 KB
testcase_52 AC 2 ms
6,944 KB
testcase_53 AC 3 ms
6,940 KB
testcase_54 AC 2 ms
6,944 KB
testcase_55 AC 2 ms
6,940 KB
testcase_56 AC 2 ms
6,940 KB
testcase_57 AC 2 ms
6,948 KB
testcase_58 AC 2 ms
6,940 KB
testcase_59 AC 2 ms
6,944 KB
testcase_60 AC 2 ms
6,944 KB
testcase_61 AC 2 ms
6,940 KB
testcase_62 AC 2 ms
6,940 KB
testcase_63 AC 6 ms
6,940 KB
testcase_64 AC 2 ms
6,940 KB
testcase_65 AC 5 ms
6,944 KB
testcase_66 AC 4 ms
6,940 KB
testcase_67 AC 2 ms
6,944 KB
testcase_68 AC 4 ms
6,944 KB
testcase_69 AC 4 ms
6,940 KB
testcase_70 AC 3 ms
6,940 KB
testcase_71 AC 3 ms
6,940 KB
testcase_72 AC 5 ms
6,944 KB
testcase_73 AC 3 ms
6,944 KB
testcase_74 AC 4 ms
6,940 KB
testcase_75 AC 4 ms
6,940 KB
testcase_76 AC 3 ms
6,940 KB
testcase_77 AC 4 ms
6,944 KB
testcase_78 AC 6 ms
6,940 KB
testcase_79 AC 5 ms
6,944 KB
testcase_80 AC 5 ms
6,940 KB
testcase_81 AC 6 ms
6,940 KB
testcase_82 AC 5 ms
6,940 KB
testcase_83 AC 54 ms
11,904 KB
testcase_84 AC 56 ms
11,776 KB
testcase_85 AC 30 ms
8,448 KB
testcase_86 AC 44 ms
10,752 KB
testcase_87 AC 49 ms
11,264 KB
testcase_88 AC 10 ms
6,940 KB
testcase_89 AC 55 ms
11,904 KB
testcase_90 AC 33 ms
8,960 KB
testcase_91 AC 27 ms
7,808 KB
testcase_92 AC 15 ms
6,944 KB
testcase_93 AC 44 ms
10,240 KB
testcase_94 AC 44 ms
9,600 KB
testcase_95 AC 41 ms
9,472 KB
testcase_96 AC 57 ms
11,520 KB
testcase_97 AC 24 ms
6,944 KB
testcase_98 AC 56 ms
11,648 KB
testcase_99 AC 30 ms
8,320 KB
testcase_100 AC 61 ms
12,212 KB
testcase_101 AC 13 ms
6,944 KB
testcase_102 AC 7 ms
6,940 KB
testcase_103 AC 15 ms
6,944 KB
testcase_104 AC 20 ms
6,944 KB
testcase_105 AC 44 ms
10,240 KB
testcase_106 AC 26 ms
7,424 KB
testcase_107 AC 58 ms
11,904 KB
testcase_108 AC 56 ms
11,904 KB
testcase_109 AC 43 ms
10,112 KB
testcase_110 AC 39 ms
9,472 KB
testcase_111 AC 40 ms
10,112 KB
testcase_112 AC 19 ms
6,940 KB
testcase_113 AC 38 ms
9,216 KB
testcase_114 AC 24 ms
7,168 KB
testcase_115 AC 9 ms
6,944 KB
testcase_116 AC 29 ms
7,808 KB
testcase_117 AC 20 ms
6,944 KB
testcase_118 AC 54 ms
11,392 KB
testcase_119 AC 32 ms
8,192 KB
testcase_120 AC 51 ms
11,264 KB
testcase_121 AC 17 ms
6,944 KB
testcase_122 AC 28 ms
7,680 KB
testcase_123 AC 2 ms
6,940 KB
testcase_124 AC 94 ms
21,432 KB
testcase_125 AC 87 ms
21,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,fma,abm,mmx,avx,avx2")
#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 all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define yn(joken) cout<<((joken) ? "Yes" : "No")<<"\n"
#define YN(joken) cout<<((joken) ? "YES" : "NO")<<"\n"
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vld = vector<long double>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvs = vector<vector<string>>;
using vvc = vector<vector<char>>;
using vvd = vector<vector<double>>;
using vvld = vector<vector<long double>>;
using vvvi = vector<vector<vector<int>>>;
using vvvl = vector<vector<vector<ll>>>;
using vvvvi = vector<vector<vector<vector<int>>>>;
using vvvvl = vector<vector<vector<vector<ll>>>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
const int INF = 1e9;
const ll LINF = 2e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
bool ispow2(int i) { return i && (i & -i) == i; }
bool ispow2(ll i) { return i && (i & -i) == i; }
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (int i = 0; i < int(v.size()); i++) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (int i = 0; i < int(v.size()); i++) {
        os << v[i];
        if (i < int(v.size()) - 1) os << ' ';
    }
    return os;
}

static uint32_t RandXor(){
    static uint32_t x=123456789;
    static uint32_t y=362436069;
    static uint32_t z=521288629;
    static uint32_t w=88675123;
    uint32_t t;
 
    t=x^(x<<11);
    x=y; y=z; z=w;
    return w=(w^(w>>19))^(t^(t>>8));
}

static long double Rand01(){
    return (RandXor()+0.5)*(1.0/UINT_MAX);
}

template <typename T = int>
struct Edge{
    int from, to;
    T cost;
    int idx;
    Edge() = default;
    Edge(int from, int to, T cost = 1, int idx = -1) : from(from), to(to), cost(cost), idx(idx) {}
    operator int() const { return to; }
};

template <typename T = int>
struct Graph{
    vector<vector<Edge<T>>> g;
    int es;
    Graph() = default;
    explicit Graph(int n) : g(n), es(0) {}
    size_t size() const{
        return g.size();
    }

    void add_directed_edge(int from, int to, T cost = 1){
        g[from].emplace_back(from, to, cost, es++);
    }

    void add_edge(int from, int to, T cost = 1){
        g[from].emplace_back(from, to, cost, es);
        g[to].emplace_back(to, from, cost, es++);
    }

    void read(int M, int padding = -1, bool weighted = false, bool directed = false){
        for (int i = 0; i < M; i++){
            int a, b;
            cin >> a >> b;
            a += padding;
            b += padding;
            T c = T(1);
            if (weighted) cin >> c;
            if (directed) add_directed_edge(a, b, c);
            else add_edge(a, b, c);
        }
    }

    inline vector<Edge<T>> &operator[](const int &k){
        return g[k];
    }

    inline const vector<Edge<T>> &operator[](const int &k) const{
        return g[k];
    }
};

template <typename T = int>
using Edges = vector<Edge<T>>;

template<typename T>
vector<int> bridge_tree_decomposition(Graph<T> &G){
    int N=(int)G.g.size();
    vector<bool> visited(N);
    vector<int> ord(N),low(N),cmp(N,-1);
    int ts=0,idx=0;
    auto dfs=[&](auto &&self,int v,int p=-1)->void{
        visited[v]=true;
        ord[v]=ts;
        low[v]=ord[v];
        ts++;
        bool flg=false;
        for(auto nv:G[v]){
            if(!visited[nv]){
                self(self,nv,v);
                low[v]=min(low[v],low[nv]);
            }
            else if(nv!=p){
                low[v]=min(low[v],ord[nv]);
            }
            else{
                if(!flg) flg=true;
                else low[v]=min(low[v],ord[p]);
            }
        }
    };
    auto dfs2=[&](auto &&self,int v)->void{
        for(auto nv:G[v]){
            if(cmp[nv]!=-1) continue;
            if(low[nv]<=ord[v]) cmp[nv]=cmp[v];
            else{
                cmp[nv]=idx;
                idx++;
            }
            self(self,nv);
        }
    };
    for(int i=0;i<N;i++) if(!visited[i]) dfs(dfs,i);    
    for(int i=0;i<N;i++){
        if(cmp[i]==-1){
            cmp[i]=idx;
            idx++;
            dfs2(dfs2,i);
        }
    }
    return cmp;
}

void solve(){
    int N;
    cin>>N;
    vi A(N),B(N);
    Graph<int> G(N);
    rep(i,N){
        cin>>A[i]>>B[i];
        A[i]--; B[i]--;
        G.add_edge(A[i],B[i]);
    }
    auto ret=bridge_tree_decomposition(G);
    vi ANS;
    rep(i,N) if(ret[A[i]]==ret[B[i]]) ANS.emplace_back(i+1);
    cout<<sz(ANS)<<endl;
    cout<<ANS<<endl;
}

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

    solve();
}
0