結果

問題 No.1254 補強への架け橋
ユーザー kyoprounokyoprouno
提出日時 2020-10-10 01:38:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 301 ms / 2,000 ms
コード長 1,850 bytes
コンパイル時間 2,769 ms
コンパイル使用メモリ 191,888 KB
実行使用メモリ 31,096 KB
最終ジャッジ日時 2023-09-27 20:44:43
合計ジャッジ時間 14,644 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 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,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 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,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 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,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 3 ms
4,376 KB
testcase_52 AC 2 ms
4,380 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 3 ms
4,380 KB
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 1 ms
4,380 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 2 ms
4,384 KB
testcase_59 AC 1 ms
4,380 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 1 ms
4,380 KB
testcase_63 AC 11 ms
4,760 KB
testcase_64 AC 4 ms
4,376 KB
testcase_65 AC 7 ms
4,380 KB
testcase_66 AC 6 ms
4,380 KB
testcase_67 AC 3 ms
4,376 KB
testcase_68 AC 7 ms
4,376 KB
testcase_69 AC 8 ms
4,400 KB
testcase_70 AC 4 ms
4,380 KB
testcase_71 AC 3 ms
4,380 KB
testcase_72 AC 9 ms
4,432 KB
testcase_73 AC 3 ms
4,380 KB
testcase_74 AC 8 ms
4,380 KB
testcase_75 AC 6 ms
4,380 KB
testcase_76 AC 3 ms
4,380 KB
testcase_77 AC 5 ms
4,380 KB
testcase_78 AC 10 ms
4,520 KB
testcase_79 AC 9 ms
4,560 KB
testcase_80 AC 9 ms
4,440 KB
testcase_81 AC 10 ms
4,732 KB
testcase_82 AC 10 ms
4,504 KB
testcase_83 AC 122 ms
17,516 KB
testcase_84 AC 119 ms
17,348 KB
testcase_85 AC 68 ms
11,700 KB
testcase_86 AC 108 ms
15,332 KB
testcase_87 AC 114 ms
16,200 KB
testcase_88 AC 16 ms
5,340 KB
testcase_89 AC 128 ms
17,336 KB
testcase_90 AC 79 ms
12,356 KB
testcase_91 AC 54 ms
10,380 KB
testcase_92 AC 27 ms
7,012 KB
testcase_93 AC 89 ms
14,600 KB
testcase_94 AC 81 ms
13,596 KB
testcase_95 AC 83 ms
13,564 KB
testcase_96 AC 111 ms
16,708 KB
testcase_97 AC 46 ms
9,340 KB
testcase_98 AC 112 ms
16,812 KB
testcase_99 AC 63 ms
11,496 KB
testcase_100 AC 124 ms
17,836 KB
testcase_101 AC 25 ms
6,844 KB
testcase_102 AC 13 ms
4,908 KB
testcase_103 AC 27 ms
7,136 KB
testcase_104 AC 38 ms
8,276 KB
testcase_105 AC 91 ms
14,744 KB
testcase_106 AC 50 ms
9,848 KB
testcase_107 AC 123 ms
17,384 KB
testcase_108 AC 117 ms
17,424 KB
testcase_109 AC 95 ms
14,400 KB
testcase_110 AC 79 ms
13,296 KB
testcase_111 AC 91 ms
14,204 KB
testcase_112 AC 36 ms
8,004 KB
testcase_113 AC 79 ms
13,112 KB
testcase_114 AC 47 ms
9,792 KB
testcase_115 AC 20 ms
5,576 KB
testcase_116 AC 62 ms
10,660 KB
testcase_117 AC 38 ms
8,088 KB
testcase_118 AC 112 ms
16,468 KB
testcase_119 AC 61 ms
11,492 KB
testcase_120 AC 105 ms
16,236 KB
testcase_121 AC 30 ms
7,612 KB
testcase_122 AC 58 ms
10,824 KB
testcase_123 AC 1 ms
4,380 KB
testcase_124 AC 279 ms
31,072 KB
testcase_125 AC 301 ms
31,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

const ll INF=1e6+1;

vector<vector<ll>> to;
vector<ll> visited,loop;

ll num=-1;

void dfs1(ll v,ll p=-1){
    if(visited[v]){
        num=v;
        return;
    }
    visited[v]=1;
    for(auto x:to[v]){
        if(x==p ) continue;
        dfs1(x,v);
    }
    return ;
}
set<ll> ans;
map<pll,ll> m;

bool dfs(ll v,ll p=-1){
    if(visited[v]){
        if(m.count({v,p})){
            ans.insert(m[{v,p}]);
        }
        if(m.count({p,v})){
            ans.insert(m[{p,v}]);
        }
        return true;
    }
    visited[v]=1;
    for(auto x:to[v]){
        if(x==p) continue;
        if(dfs(x,v)){
            if(m.count({v,p})){
                ans.insert(m[{v,p}]);
            }
            if(m.count({p,v})){
                ans.insert(m[{p,v}]);
            }
            return true;
        }
    }
    return false;
}


int main(){
    ll n;
    cin >> n ;
    vector<ll> a(n),b(n);
    to=vector<vector<ll>>(n);
    visited=vector<ll>(n);
    
    rep(i,n){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        to[a[i]].push_back(b[i]);
        to[b[i]].push_back(a[i]);
        m[{a[i],b[i]}]=i;
    }
    dfs1(0LL);
    visited=vector<ll>(n);
    dfs(num);
    cout << ans.size() << endl;
    ll i=0;
    for(auto x:ans){
        if(i) cout << " ";
        cout << x+1;
        i++;
    }
    cout << endl;
    return 0;
}
0