結果

問題 No.1254 補強への架け橋
ユーザー どららどらら
提出日時 2020-10-09 23:06:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 436 ms / 2,000 ms
コード長 1,710 bytes
コンパイル時間 1,752 ms
コンパイル使用メモリ 183,540 KB
実行使用メモリ 31,744 KB
最終ジャッジ日時 2023-09-27 19:28:51
合計ジャッジ時間 16,695 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,532 KB
testcase_01 AC 4 ms
6,460 KB
testcase_02 AC 4 ms
6,528 KB
testcase_03 AC 4 ms
6,452 KB
testcase_04 AC 4 ms
6,604 KB
testcase_05 AC 4 ms
6,744 KB
testcase_06 AC 4 ms
6,452 KB
testcase_07 AC 4 ms
6,532 KB
testcase_08 AC 4 ms
6,432 KB
testcase_09 AC 4 ms
6,436 KB
testcase_10 AC 4 ms
6,504 KB
testcase_11 AC 4 ms
6,516 KB
testcase_12 AC 4 ms
6,456 KB
testcase_13 AC 4 ms
6,616 KB
testcase_14 AC 4 ms
6,464 KB
testcase_15 AC 4 ms
6,764 KB
testcase_16 AC 4 ms
6,452 KB
testcase_17 AC 4 ms
6,568 KB
testcase_18 AC 4 ms
6,456 KB
testcase_19 AC 4 ms
6,512 KB
testcase_20 AC 4 ms
6,500 KB
testcase_21 AC 4 ms
6,428 KB
testcase_22 AC 4 ms
6,540 KB
testcase_23 AC 4 ms
6,748 KB
testcase_24 AC 4 ms
6,756 KB
testcase_25 AC 4 ms
6,468 KB
testcase_26 AC 4 ms
6,448 KB
testcase_27 AC 4 ms
6,756 KB
testcase_28 AC 4 ms
6,488 KB
testcase_29 AC 4 ms
6,464 KB
testcase_30 AC 4 ms
6,428 KB
testcase_31 AC 5 ms
6,620 KB
testcase_32 AC 4 ms
6,432 KB
testcase_33 AC 4 ms
6,532 KB
testcase_34 AC 4 ms
6,560 KB
testcase_35 AC 4 ms
6,444 KB
testcase_36 AC 5 ms
6,444 KB
testcase_37 AC 4 ms
6,708 KB
testcase_38 AC 4 ms
6,548 KB
testcase_39 AC 4 ms
6,572 KB
testcase_40 AC 4 ms
6,432 KB
testcase_41 AC 5 ms
6,452 KB
testcase_42 AC 4 ms
6,464 KB
testcase_43 AC 5 ms
6,568 KB
testcase_44 AC 4 ms
6,516 KB
testcase_45 AC 4 ms
6,472 KB
testcase_46 AC 5 ms
6,632 KB
testcase_47 AC 4 ms
6,524 KB
testcase_48 AC 5 ms
6,612 KB
testcase_49 AC 4 ms
6,476 KB
testcase_50 AC 5 ms
6,596 KB
testcase_51 AC 5 ms
6,884 KB
testcase_52 AC 5 ms
6,708 KB
testcase_53 AC 5 ms
6,552 KB
testcase_54 AC 5 ms
6,596 KB
testcase_55 AC 5 ms
6,600 KB
testcase_56 AC 4 ms
6,484 KB
testcase_57 AC 5 ms
6,612 KB
testcase_58 AC 5 ms
6,544 KB
testcase_59 AC 4 ms
6,460 KB
testcase_60 AC 4 ms
6,592 KB
testcase_61 AC 5 ms
6,560 KB
testcase_62 AC 4 ms
6,452 KB
testcase_63 AC 18 ms
8,168 KB
testcase_64 AC 7 ms
6,920 KB
testcase_65 AC 12 ms
7,500 KB
testcase_66 AC 11 ms
7,244 KB
testcase_67 AC 6 ms
6,768 KB
testcase_68 AC 11 ms
7,336 KB
testcase_69 AC 14 ms
7,588 KB
testcase_70 AC 8 ms
6,940 KB
testcase_71 AC 7 ms
6,904 KB
testcase_72 AC 14 ms
7,596 KB
testcase_73 AC 8 ms
6,904 KB
testcase_74 AC 13 ms
7,704 KB
testcase_75 AC 11 ms
7,252 KB
testcase_76 AC 6 ms
6,716 KB
testcase_77 AC 11 ms
7,220 KB
testcase_78 AC 17 ms
7,984 KB
testcase_79 AC 17 ms
7,896 KB
testcase_80 AC 15 ms
7,756 KB
testcase_81 AC 17 ms
7,920 KB
testcase_82 AC 16 ms
7,872 KB
testcase_83 AC 244 ms
21,300 KB
testcase_84 AC 223 ms
20,760 KB
testcase_85 AC 124 ms
15,420 KB
testcase_86 AC 191 ms
18,900 KB
testcase_87 AC 216 ms
20,056 KB
testcase_88 AC 26 ms
8,736 KB
testcase_89 AC 235 ms
21,236 KB
testcase_90 AC 137 ms
15,964 KB
testcase_91 AC 102 ms
14,068 KB
testcase_92 AC 47 ms
10,632 KB
testcase_93 AC 181 ms
18,216 KB
testcase_94 AC 159 ms
17,116 KB
testcase_95 AC 162 ms
17,112 KB
testcase_96 AC 224 ms
20,388 KB
testcase_97 AC 85 ms
12,844 KB
testcase_98 AC 225 ms
20,468 KB
testcase_99 AC 123 ms
15,068 KB
testcase_100 AC 244 ms
21,512 KB
testcase_101 AC 40 ms
10,128 KB
testcase_102 AC 22 ms
8,364 KB
testcase_103 AC 44 ms
10,428 KB
testcase_104 AC 67 ms
12,036 KB
testcase_105 AC 186 ms
18,540 KB
testcase_106 AC 93 ms
13,556 KB
testcase_107 AC 246 ms
21,076 KB
testcase_108 AC 235 ms
20,936 KB
testcase_109 AC 180 ms
18,164 KB
testcase_110 AC 151 ms
17,160 KB
testcase_111 AC 169 ms
17,768 KB
testcase_112 AC 62 ms
11,608 KB
testcase_113 AC 154 ms
16,720 KB
testcase_114 AC 87 ms
13,232 KB
testcase_115 AC 28 ms
8,964 KB
testcase_116 AC 110 ms
14,288 KB
testcase_117 AC 67 ms
11,620 KB
testcase_118 AC 210 ms
20,332 KB
testcase_119 AC 123 ms
15,256 KB
testcase_120 AC 213 ms
19,816 KB
testcase_121 AC 53 ms
11,124 KB
testcase_122 AC 104 ms
14,152 KB
testcase_123 AC 4 ms
6,432 KB
testcase_124 AC 436 ms
31,744 KB
testcase_125 AC 428 ms
31,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int N;
vector<int> G[100005];
map<pair<int,int>,int> memo;
int level[100005];
int parent[100005];
int reta, retb;

void dfs(int v, int l, int p){
  level[v] = l;
  parent[v] = p;

  rep(i,G[v].size()){
    if(reta != -1) return;
    
    int nxt = G[v][i];
    if(nxt == p) continue;

    if(level[nxt] != -1){
      reta = v;
      retb = nxt;
      return;
    }
    dfs(nxt, l+1, v);
  }
}


int main(){
  cin >> N;
  rep(i,N){
    int a, b;
    cin >> a >> b;
    memo[make_pair(a,b)] = i+1;
    memo[make_pair(b,a)] = i+1;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  rep(i,100005){
    level[i] = -1;
    parent[i] = -1;
  }
  reta = -1;
  retb = -1;
  
  dfs(1, 0, -1);

  map<int,int> used;
  used[memo[make_pair(reta,retb)]] = 1;
  while(reta != retb){
    if(level[reta] > level[retb]){
      used[memo[make_pair(reta,parent[reta])]] = 1;
      reta = parent[reta];
    }
    else if(level[reta] < level[retb]){
      used[memo[make_pair(retb,parent[retb])]] = 1;
      retb = parent[retb];
    }
    else{
      used[memo[make_pair(reta,parent[reta])]] = 1;
      reta = parent[reta];
      used[memo[make_pair(retb,parent[retb])]] = 1;
      retb = parent[retb];
    }
  }

  vector<int> ret;
  REP(i,1,N+1){
    if(used.count(i) > 0) ret.push_back(i);
  }

  cout << ret.size() << endl;
  rep(i,ret.size()){
    if(i>0) cout << " ";
    cout << ret[i];
  }
  cout << endl;
  return 0;
}

0