結果

問題 No.1254 補強への架け橋
ユーザー msm1993msm1993
提出日時 2020-10-23 15:27:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 1,517 bytes
コンパイル時間 951 ms
コンパイル使用メモリ 94,800 KB
実行使用メモリ 10,652 KB
最終ジャッジ日時 2023-09-28 15:23:36
合計ジャッジ時間 12,105 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,304 KB
testcase_01 AC 3 ms
6,228 KB
testcase_02 AC 4 ms
6,460 KB
testcase_03 AC 4 ms
6,504 KB
testcase_04 AC 4 ms
6,288 KB
testcase_05 AC 4 ms
6,196 KB
testcase_06 AC 4 ms
6,344 KB
testcase_07 AC 4 ms
6,304 KB
testcase_08 AC 4 ms
6,248 KB
testcase_09 AC 3 ms
6,304 KB
testcase_10 AC 4 ms
6,336 KB
testcase_11 AC 3 ms
6,216 KB
testcase_12 AC 4 ms
6,292 KB
testcase_13 AC 3 ms
6,272 KB
testcase_14 AC 4 ms
6,200 KB
testcase_15 AC 4 ms
6,280 KB
testcase_16 AC 3 ms
6,272 KB
testcase_17 AC 4 ms
6,244 KB
testcase_18 AC 3 ms
6,308 KB
testcase_19 AC 4 ms
6,272 KB
testcase_20 AC 4 ms
6,196 KB
testcase_21 AC 3 ms
6,288 KB
testcase_22 AC 3 ms
6,312 KB
testcase_23 AC 4 ms
6,288 KB
testcase_24 AC 3 ms
6,364 KB
testcase_25 AC 4 ms
6,288 KB
testcase_26 AC 4 ms
6,296 KB
testcase_27 AC 4 ms
6,196 KB
testcase_28 AC 4 ms
6,400 KB
testcase_29 AC 4 ms
6,276 KB
testcase_30 AC 4 ms
6,276 KB
testcase_31 AC 4 ms
6,540 KB
testcase_32 AC 4 ms
6,204 KB
testcase_33 AC 4 ms
6,424 KB
testcase_34 AC 4 ms
6,196 KB
testcase_35 AC 4 ms
6,344 KB
testcase_36 AC 3 ms
6,496 KB
testcase_37 AC 3 ms
6,256 KB
testcase_38 AC 3 ms
6,288 KB
testcase_39 AC 4 ms
6,296 KB
testcase_40 AC 4 ms
6,268 KB
testcase_41 AC 4 ms
6,300 KB
testcase_42 AC 4 ms
6,224 KB
testcase_43 AC 4 ms
6,300 KB
testcase_44 AC 4 ms
6,328 KB
testcase_45 AC 4 ms
6,208 KB
testcase_46 AC 4 ms
6,316 KB
testcase_47 AC 4 ms
6,384 KB
testcase_48 AC 4 ms
6,392 KB
testcase_49 AC 4 ms
6,196 KB
testcase_50 AC 4 ms
6,236 KB
testcase_51 AC 4 ms
6,292 KB
testcase_52 AC 4 ms
6,252 KB
testcase_53 AC 4 ms
6,372 KB
testcase_54 AC 4 ms
6,256 KB
testcase_55 AC 4 ms
6,224 KB
testcase_56 AC 4 ms
6,276 KB
testcase_57 AC 4 ms
6,224 KB
testcase_58 AC 4 ms
6,484 KB
testcase_59 AC 4 ms
6,232 KB
testcase_60 AC 4 ms
6,388 KB
testcase_61 AC 4 ms
6,304 KB
testcase_62 AC 3 ms
6,276 KB
testcase_63 AC 7 ms
6,636 KB
testcase_64 AC 4 ms
6,516 KB
testcase_65 AC 6 ms
6,572 KB
testcase_66 AC 5 ms
6,684 KB
testcase_67 AC 4 ms
6,484 KB
testcase_68 AC 5 ms
6,532 KB
testcase_69 AC 6 ms
6,636 KB
testcase_70 AC 5 ms
6,360 KB
testcase_71 AC 5 ms
6,352 KB
testcase_72 AC 6 ms
6,532 KB
testcase_73 AC 4 ms
6,392 KB
testcase_74 AC 6 ms
6,580 KB
testcase_75 AC 5 ms
6,532 KB
testcase_76 AC 4 ms
6,300 KB
testcase_77 AC 5 ms
6,452 KB
testcase_78 AC 7 ms
6,648 KB
testcase_79 AC 7 ms
6,664 KB
testcase_80 AC 6 ms
6,544 KB
testcase_81 AC 6 ms
6,604 KB
testcase_82 AC 7 ms
6,656 KB
testcase_83 AC 57 ms
10,428 KB
testcase_84 AC 51 ms
10,304 KB
testcase_85 AC 28 ms
8,944 KB
testcase_86 AC 41 ms
9,872 KB
testcase_87 AC 51 ms
10,180 KB
testcase_88 AC 9 ms
6,908 KB
testcase_89 AC 49 ms
10,464 KB
testcase_90 AC 32 ms
9,256 KB
testcase_91 AC 23 ms
8,432 KB
testcase_92 AC 14 ms
7,420 KB
testcase_93 AC 38 ms
9,568 KB
testcase_94 AC 42 ms
9,264 KB
testcase_95 AC 34 ms
9,456 KB
testcase_96 AC 52 ms
10,276 KB
testcase_97 AC 21 ms
8,128 KB
testcase_98 AC 53 ms
10,328 KB
testcase_99 AC 29 ms
8,672 KB
testcase_100 AC 48 ms
10,652 KB
testcase_101 AC 12 ms
7,312 KB
testcase_102 AC 8 ms
6,768 KB
testcase_103 AC 15 ms
7,356 KB
testcase_104 AC 17 ms
7,784 KB
testcase_105 AC 39 ms
9,704 KB
testcase_106 AC 23 ms
8,364 KB
testcase_107 AC 52 ms
10,412 KB
testcase_108 AC 54 ms
10,544 KB
testcase_109 AC 44 ms
9,536 KB
testcase_110 AC 35 ms
9,376 KB
testcase_111 AC 41 ms
9,488 KB
testcase_112 AC 18 ms
7,764 KB
testcase_113 AC 33 ms
9,164 KB
testcase_114 AC 22 ms
8,196 KB
testcase_115 AC 10 ms
7,236 KB
testcase_116 AC 29 ms
8,712 KB
testcase_117 AC 18 ms
7,772 KB
testcase_118 AC 42 ms
10,352 KB
testcase_119 AC 30 ms
8,752 KB
testcase_120 AC 45 ms
10,052 KB
testcase_121 AC 16 ms
7,528 KB
testcase_122 AC 23 ms
8,548 KB
testcase_123 AC 4 ms
6,264 KB
testcase_124 AC 75 ms
10,528 KB
testcase_125 AC 76 ms
10,500 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