結果

問題 No.1254 補強への架け橋
ユーザー tnakao0123tnakao0123
提出日時 2020-10-10 01:51:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,517 bytes
コンパイル時間 916 ms
コンパイル使用メモリ 94,700 KB
実行使用メモリ 10,608 KB
最終ジャッジ日時 2023-09-27 20:53:18
合計ジャッジ時間 10,664 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,248 KB
testcase_01 AC 4 ms
6,380 KB
testcase_02 AC 3 ms
6,272 KB
testcase_03 AC 4 ms
6,172 KB
testcase_04 AC 3 ms
6,304 KB
testcase_05 AC 4 ms
6,264 KB
testcase_06 AC 4 ms
6,268 KB
testcase_07 AC 4 ms
6,364 KB
testcase_08 AC 3 ms
6,196 KB
testcase_09 AC 3 ms
6,180 KB
testcase_10 AC 4 ms
6,332 KB
testcase_11 AC 4 ms
6,304 KB
testcase_12 AC 4 ms
6,260 KB
testcase_13 AC 4 ms
6,252 KB
testcase_14 AC 3 ms
6,188 KB
testcase_15 AC 3 ms
6,248 KB
testcase_16 AC 4 ms
6,184 KB
testcase_17 AC 4 ms
6,248 KB
testcase_18 AC 4 ms
6,380 KB
testcase_19 AC 3 ms
6,520 KB
testcase_20 AC 3 ms
6,276 KB
testcase_21 AC 4 ms
6,180 KB
testcase_22 AC 3 ms
6,328 KB
testcase_23 AC 4 ms
6,332 KB
testcase_24 AC 4 ms
6,268 KB
testcase_25 AC 4 ms
6,272 KB
testcase_26 AC 4 ms
6,380 KB
testcase_27 AC 3 ms
6,300 KB
testcase_28 AC 4 ms
6,268 KB
testcase_29 AC 4 ms
6,268 KB
testcase_30 AC 3 ms
6,332 KB
testcase_31 AC 4 ms
6,272 KB
testcase_32 AC 4 ms
6,204 KB
testcase_33 AC 4 ms
6,276 KB
testcase_34 AC 4 ms
6,328 KB
testcase_35 AC 3 ms
6,332 KB
testcase_36 AC 4 ms
6,252 KB
testcase_37 AC 4 ms
6,388 KB
testcase_38 AC 4 ms
6,268 KB
testcase_39 AC 3 ms
6,172 KB
testcase_40 AC 3 ms
6,188 KB
testcase_41 AC 4 ms
6,244 KB
testcase_42 AC 4 ms
6,220 KB
testcase_43 AC 4 ms
6,508 KB
testcase_44 AC 4 ms
6,192 KB
testcase_45 AC 3 ms
6,436 KB
testcase_46 AC 4 ms
6,364 KB
testcase_47 AC 4 ms
6,292 KB
testcase_48 AC 4 ms
6,360 KB
testcase_49 AC 4 ms
6,200 KB
testcase_50 AC 4 ms
6,532 KB
testcase_51 AC 4 ms
6,224 KB
testcase_52 AC 4 ms
6,244 KB
testcase_53 AC 4 ms
6,412 KB
testcase_54 AC 4 ms
6,352 KB
testcase_55 AC 4 ms
6,236 KB
testcase_56 AC 4 ms
6,396 KB
testcase_57 AC 4 ms
6,236 KB
testcase_58 AC 4 ms
6,356 KB
testcase_59 AC 3 ms
6,208 KB
testcase_60 AC 4 ms
6,268 KB
testcase_61 AC 4 ms
6,420 KB
testcase_62 AC 4 ms
6,508 KB
testcase_63 AC 7 ms
6,716 KB
testcase_64 AC 5 ms
6,324 KB
testcase_65 AC 6 ms
6,548 KB
testcase_66 AC 6 ms
6,524 KB
testcase_67 AC 4 ms
6,276 KB
testcase_68 AC 5 ms
6,440 KB
testcase_69 AC 7 ms
6,688 KB
testcase_70 AC 5 ms
6,320 KB
testcase_71 AC 4 ms
6,284 KB
testcase_72 AC 6 ms
6,608 KB
testcase_73 AC 5 ms
6,400 KB
testcase_74 AC 6 ms
6,620 KB
testcase_75 AC 5 ms
6,560 KB
testcase_76 AC 4 ms
6,292 KB
testcase_77 AC 5 ms
6,496 KB
testcase_78 AC 7 ms
6,772 KB
testcase_79 AC 7 ms
6,684 KB
testcase_80 AC 6 ms
6,540 KB
testcase_81 AC 6 ms
6,584 KB
testcase_82 AC 6 ms
6,588 KB
testcase_83 AC 52 ms
10,416 KB
testcase_84 AC 46 ms
10,412 KB
testcase_85 AC 28 ms
8,768 KB
testcase_86 AC 43 ms
9,832 KB
testcase_87 AC 41 ms
10,164 KB
testcase_88 AC 9 ms
6,812 KB
testcase_89 AC 47 ms
10,464 KB
testcase_90 AC 28 ms
9,020 KB
testcase_91 AC 24 ms
8,540 KB
testcase_92 AC 13 ms
7,336 KB
testcase_93 AC 36 ms
9,624 KB
testcase_94 AC 35 ms
9,336 KB
testcase_95 AC 34 ms
9,304 KB
testcase_96 AC 50 ms
10,176 KB
testcase_97 AC 21 ms
8,092 KB
testcase_98 AC 45 ms
10,272 KB
testcase_99 AC 26 ms
8,748 KB
testcase_100 AC 48 ms
10,608 KB
testcase_101 AC 12 ms
7,212 KB
testcase_102 AC 8 ms
6,728 KB
testcase_103 AC 14 ms
7,408 KB
testcase_104 AC 17 ms
7,808 KB
testcase_105 AC 37 ms
9,568 KB
testcase_106 AC 22 ms
8,312 KB
testcase_107 AC 51 ms
10,472 KB
testcase_108 AC 46 ms
10,408 KB
testcase_109 AC 39 ms
9,648 KB
testcase_110 AC 32 ms
9,444 KB
testcase_111 AC 39 ms
9,424 KB
testcase_112 AC 17 ms
7,652 KB
testcase_113 AC 32 ms
9,208 KB
testcase_114 AC 22 ms
8,280 KB
testcase_115 AC 9 ms
7,016 KB
testcase_116 AC 27 ms
8,536 KB
testcase_117 AC 18 ms
7,744 KB
testcase_118 AC 44 ms
10,148 KB
testcase_119 AC 28 ms
8,712 KB
testcase_120 AC 43 ms
10,080 KB
testcase_121 AC 15 ms
7,600 KB
testcase_122 AC 24 ms
8,396 KB
testcase_123 AC 3 ms
6,184 KB
testcase_124 AC 68 ms
10,548 KB
testcase_125 AC 71 ms
10,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1254.cc:  No.1254 補強への架け橋 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef pair<int,int> pii;
typedef vector<pii> vpii;

/* global variables */

vpii nbrs[MAX_N];
int ps[MAX_N], ds[MAX_N], cis[MAX_N];
int es[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    nbrs[a].push_back(pii(b, i));
    nbrs[b].push_back(pii(a, i));
  }

  memset(ds, -1, sizeof(ds));
  ps[0] = -1, ds[0] = 1;

  int l = -1, r = -1;
  for (int u = 0; u >= 0;) {
    if (cis[u] < nbrs[u].size() && nbrs[u][cis[u]].first == ps[u])
      cis[u]++;
    if (cis[u] < nbrs[u].size()) {
      pii a = nbrs[u][cis[u]++];
      int v = a.first, ei = a.second;
      es[ds[u]] = ei;
      if (ds[v] < 0) {
	ps[v] = u, ds[v] = ds[u] + 1;
	u = v;
      }
      else {
	l = ds[v], r = ds[u] + 1;
	break;
      }
    }
    else
      u = ps[u];
  }
  //printf("l=%d, r=%d\n", l, r);

  printf("%d\n", r - l);
  for (int i = l; i < r; i++) {
    printf("%d", es[i] + 1);
    putchar(i + 1 < r ? ' ' : '\n');
  }
  return 0;
}
0