結果

問題 No.1254 補強への架け橋
ユーザー ゆにぽけゆにぽけ
提出日時 2023-10-25 11:35:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 205 ms / 2,000 ms
コード長 1,261 bytes
コンパイル時間 1,568 ms
コンパイル使用メモリ 138,804 KB
実行使用メモリ 25,100 KB
最終ジャッジ日時 2023-10-25 11:35:43
合計ジャッジ時間 16,741 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,668 KB
testcase_01 AC 3 ms
6,668 KB
testcase_02 AC 3 ms
6,668 KB
testcase_03 AC 3 ms
6,668 KB
testcase_04 AC 3 ms
6,668 KB
testcase_05 AC 3 ms
6,668 KB
testcase_06 AC 3 ms
6,668 KB
testcase_07 AC 3 ms
6,668 KB
testcase_08 AC 3 ms
6,668 KB
testcase_09 AC 4 ms
6,668 KB
testcase_10 AC 3 ms
6,668 KB
testcase_11 AC 3 ms
6,668 KB
testcase_12 AC 3 ms
6,668 KB
testcase_13 AC 4 ms
6,676 KB
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 3 ms
6,668 KB
testcase_16 AC 3 ms
6,668 KB
testcase_17 AC 4 ms
6,668 KB
testcase_18 AC 3 ms
6,668 KB
testcase_19 AC 3 ms
6,668 KB
testcase_20 AC 4 ms
6,676 KB
testcase_21 AC 3 ms
6,668 KB
testcase_22 AC 4 ms
6,668 KB
testcase_23 AC 3 ms
6,668 KB
testcase_24 AC 3 ms
6,676 KB
testcase_25 AC 3 ms
6,668 KB
testcase_26 AC 4 ms
6,680 KB
testcase_27 AC 3 ms
6,672 KB
testcase_28 AC 3 ms
6,676 KB
testcase_29 AC 3 ms
6,672 KB
testcase_30 AC 3 ms
6,668 KB
testcase_31 AC 3 ms
6,676 KB
testcase_32 AC 3 ms
6,668 KB
testcase_33 AC 3 ms
6,680 KB
testcase_34 AC 4 ms
6,680 KB
testcase_35 AC 3 ms
6,680 KB
testcase_36 AC 4 ms
6,676 KB
testcase_37 AC 4 ms
6,676 KB
testcase_38 AC 4 ms
6,676 KB
testcase_39 AC 4 ms
6,672 KB
testcase_40 AC 3 ms
6,676 KB
testcase_41 AC 3 ms
6,672 KB
testcase_42 AC 4 ms
6,668 KB
testcase_43 AC 4 ms
6,756 KB
testcase_44 AC 3 ms
6,704 KB
testcase_45 AC 4 ms
6,700 KB
testcase_46 AC 4 ms
6,744 KB
testcase_47 AC 3 ms
6,716 KB
testcase_48 AC 4 ms
6,732 KB
testcase_49 AC 4 ms
6,680 KB
testcase_50 AC 4 ms
6,764 KB
testcase_51 AC 4 ms
6,760 KB
testcase_52 AC 4 ms
6,764 KB
testcase_53 AC 4 ms
6,744 KB
testcase_54 AC 4 ms
6,760 KB
testcase_55 AC 4 ms
6,744 KB
testcase_56 AC 4 ms
6,688 KB
testcase_57 AC 4 ms
6,728 KB
testcase_58 AC 4 ms
6,732 KB
testcase_59 AC 3 ms
6,680 KB
testcase_60 AC 4 ms
6,700 KB
testcase_61 AC 4 ms
6,748 KB
testcase_62 AC 3 ms
6,684 KB
testcase_63 AC 10 ms
7,680 KB
testcase_64 AC 5 ms
6,932 KB
testcase_65 AC 8 ms
7,324 KB
testcase_66 AC 6 ms
7,184 KB
testcase_67 AC 5 ms
6,872 KB
testcase_68 AC 7 ms
7,240 KB
testcase_69 AC 8 ms
7,412 KB
testcase_70 AC 6 ms
6,988 KB
testcase_71 AC 5 ms
6,912 KB
testcase_72 AC 8 ms
7,432 KB
testcase_73 AC 5 ms
6,952 KB
testcase_74 AC 8 ms
7,388 KB
testcase_75 AC 7 ms
7,208 KB
testcase_76 AC 4 ms
6,788 KB
testcase_77 AC 6 ms
7,120 KB
testcase_78 AC 9 ms
7,568 KB
testcase_79 AC 9 ms
7,608 KB
testcase_80 AC 9 ms
7,476 KB
testcase_81 AC 11 ms
7,612 KB
testcase_82 AC 9 ms
7,540 KB
testcase_83 AC 118 ms
16,284 KB
testcase_84 AC 116 ms
16,020 KB
testcase_85 AC 55 ms
12,540 KB
testcase_86 AC 88 ms
14,784 KB
testcase_87 AC 103 ms
15,520 KB
testcase_88 AC 14 ms
8,128 KB
testcase_89 AC 109 ms
16,208 KB
testcase_90 AC 67 ms
12,856 KB
testcase_91 AC 44 ms
11,576 KB
testcase_92 AC 22 ms
9,292 KB
testcase_93 AC 79 ms
14,356 KB
testcase_94 AC 74 ms
13,644 KB
testcase_95 AC 72 ms
13,624 KB
testcase_96 AC 106 ms
15,744 KB
testcase_97 AC 39 ms
10,856 KB
testcase_98 AC 120 ms
15,832 KB
testcase_99 AC 54 ms
12,304 KB
testcase_100 AC 110 ms
16,472 KB
testcase_101 AC 21 ms
9,016 KB
testcase_102 AC 13 ms
7,916 KB
testcase_103 AC 22 ms
9,256 KB
testcase_104 AC 32 ms
10,208 KB
testcase_105 AC 88 ms
14,364 KB
testcase_106 AC 42 ms
11,244 KB
testcase_107 AC 118 ms
16,228 KB
testcase_108 AC 123 ms
16,084 KB
testcase_109 AC 88 ms
14,272 KB
testcase_110 AC 66 ms
13,556 KB
testcase_111 AC 86 ms
14,040 KB
testcase_112 AC 31 ms
10,028 KB
testcase_113 AC 71 ms
13,360 KB
testcase_114 AC 43 ms
11,104 KB
testcase_115 AC 15 ms
8,268 KB
testcase_116 AC 56 ms
11,788 KB
testcase_117 AC 35 ms
10,040 KB
testcase_118 AC 120 ms
15,668 KB
testcase_119 AC 50 ms
12,228 KB
testcase_120 AC 100 ms
15,388 KB
testcase_121 AC 26 ms
9,548 KB
testcase_122 AC 48 ms
11,684 KB
testcase_123 AC 3 ms
6,668 KB
testcase_124 AC 202 ms
25,100 KB
testcase_125 AC 205 ms
25,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cassert>
#include<cmath>
#include<ctime>
#include<iomanip>
#include<numeric>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<random>
#include<functional>
#include<utility>
using namespace std;
int N,s,seen[1 << 17],finished[1 << 17];
vector<int> G[1 << 17],path;
void dfs(int u,int p)
{
	seen[u] = 1;
	path.push_back(u);
	for(int v:G[u]) if(!finished[v] && v != p)
	{
		if(seen[v]) s = v;
		else dfs(v,u);
		if(s >= 0) return;
	}
	finished[u] = 1;
	path.pop_back();
}
void solve()
{
	cin >> N;
	map<pair<int,int>,int> E;
	for(int i = 0;i < N;i++)
	{
		int u,v;
		cin >> u >> v;
		u--; v--;
		G[u].push_back(v);
		G[v].push_back(u);
		E[minmax(u,v)] = i;
	}
	s = -1;
	dfs(0,-1);
	vector<int> cycle;
	while(true)
	{
		int u = path.back();
		cycle.push_back(u);
		if(u == s) break;
		path.pop_back();
	}
	cout << cycle.size() << endl;
	for(int i = 0;i < (int)cycle.size();i++) cout << E[minmax(cycle[i],cycle[(i+1)%(int)cycle.size()])]+1 << (i+1 == (int)cycle.size() ? "\n":" ");
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	//cin >> tt;
	while(tt--) solve();
}
0