結果

問題 No.1254 補強への架け橋
ユーザー cn_449cn_449
提出日時 2020-10-09 23:43:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 2,614 bytes
コンパイル時間 1,322 ms
コンパイル使用メモリ 143,088 KB
実行使用メモリ 29,948 KB
最終ジャッジ日時 2023-09-27 20:04:31
合計ジャッジ時間 12,998 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,668 KB
testcase_01 AC 4 ms
5,736 KB
testcase_02 AC 4 ms
5,736 KB
testcase_03 AC 3 ms
5,548 KB
testcase_04 AC 3 ms
5,544 KB
testcase_05 AC 3 ms
5,668 KB
testcase_06 AC 3 ms
5,860 KB
testcase_07 AC 2 ms
5,732 KB
testcase_08 AC 2 ms
5,512 KB
testcase_09 AC 3 ms
5,528 KB
testcase_10 AC 3 ms
5,520 KB
testcase_11 AC 3 ms
5,756 KB
testcase_12 AC 3 ms
5,852 KB
testcase_13 AC 3 ms
5,548 KB
testcase_14 AC 4 ms
5,532 KB
testcase_15 AC 3 ms
5,520 KB
testcase_16 AC 3 ms
5,544 KB
testcase_17 AC 3 ms
5,616 KB
testcase_18 AC 3 ms
5,624 KB
testcase_19 AC 3 ms
5,752 KB
testcase_20 AC 3 ms
5,624 KB
testcase_21 AC 3 ms
5,664 KB
testcase_22 AC 4 ms
5,552 KB
testcase_23 AC 4 ms
5,604 KB
testcase_24 AC 3 ms
5,560 KB
testcase_25 AC 3 ms
5,540 KB
testcase_26 AC 3 ms
5,532 KB
testcase_27 AC 3 ms
5,684 KB
testcase_28 AC 3 ms
5,536 KB
testcase_29 AC 4 ms
5,732 KB
testcase_30 AC 3 ms
5,688 KB
testcase_31 AC 3 ms
6,004 KB
testcase_32 AC 3 ms
5,620 KB
testcase_33 AC 4 ms
5,532 KB
testcase_34 AC 3 ms
6,008 KB
testcase_35 AC 4 ms
5,952 KB
testcase_36 AC 4 ms
5,996 KB
testcase_37 AC 3 ms
5,716 KB
testcase_38 AC 3 ms
5,704 KB
testcase_39 AC 2 ms
5,524 KB
testcase_40 AC 3 ms
5,996 KB
testcase_41 AC 4 ms
6,104 KB
testcase_42 AC 3 ms
5,536 KB
testcase_43 AC 4 ms
5,932 KB
testcase_44 AC 3 ms
5,948 KB
testcase_45 AC 3 ms
5,944 KB
testcase_46 AC 4 ms
5,936 KB
testcase_47 AC 4 ms
5,952 KB
testcase_48 AC 4 ms
5,848 KB
testcase_49 AC 3 ms
5,948 KB
testcase_50 AC 4 ms
5,892 KB
testcase_51 AC 4 ms
5,764 KB
testcase_52 AC 4 ms
5,764 KB
testcase_53 AC 4 ms
6,196 KB
testcase_54 AC 4 ms
6,108 KB
testcase_55 AC 4 ms
5,944 KB
testcase_56 AC 4 ms
6,116 KB
testcase_57 AC 4 ms
5,952 KB
testcase_58 AC 4 ms
5,948 KB
testcase_59 AC 3 ms
5,876 KB
testcase_60 AC 4 ms
6,012 KB
testcase_61 AC 4 ms
5,684 KB
testcase_62 AC 4 ms
5,944 KB
testcase_63 AC 12 ms
7,332 KB
testcase_64 AC 5 ms
6,124 KB
testcase_65 AC 10 ms
6,724 KB
testcase_66 AC 9 ms
6,548 KB
testcase_67 AC 5 ms
6,216 KB
testcase_68 AC 8 ms
6,588 KB
testcase_69 AC 10 ms
7,036 KB
testcase_70 AC 6 ms
6,204 KB
testcase_71 AC 6 ms
6,260 KB
testcase_72 AC 11 ms
6,920 KB
testcase_73 AC 5 ms
6,212 KB
testcase_74 AC 9 ms
6,924 KB
testcase_75 AC 8 ms
6,660 KB
testcase_76 AC 5 ms
5,868 KB
testcase_77 AC 6 ms
6,380 KB
testcase_78 AC 12 ms
7,308 KB
testcase_79 AC 13 ms
7,184 KB
testcase_80 AC 11 ms
6,948 KB
testcase_81 AC 12 ms
7,192 KB
testcase_82 AC 12 ms
7,004 KB
testcase_83 AC 141 ms
20,672 KB
testcase_84 AC 151 ms
20,196 KB
testcase_85 AC 82 ms
14,972 KB
testcase_86 AC 115 ms
18,404 KB
testcase_87 AC 150 ms
19,264 KB
testcase_88 AC 18 ms
8,100 KB
testcase_89 AC 150 ms
20,388 KB
testcase_90 AC 80 ms
15,260 KB
testcase_91 AC 65 ms
13,392 KB
testcase_92 AC 32 ms
9,908 KB
testcase_93 AC 117 ms
17,508 KB
testcase_94 AC 103 ms
16,412 KB
testcase_95 AC 97 ms
16,460 KB
testcase_96 AC 140 ms
19,660 KB
testcase_97 AC 53 ms
12,332 KB
testcase_98 AC 145 ms
20,004 KB
testcase_99 AC 81 ms
14,648 KB
testcase_100 AC 159 ms
20,684 KB
testcase_101 AC 29 ms
9,428 KB
testcase_102 AC 18 ms
7,748 KB
testcase_103 AC 34 ms
9,628 KB
testcase_104 AC 45 ms
11,148 KB
testcase_105 AC 120 ms
17,504 KB
testcase_106 AC 60 ms
12,732 KB
testcase_107 AC 159 ms
20,408 KB
testcase_108 AC 156 ms
20,280 KB
testcase_109 AC 111 ms
17,604 KB
testcase_110 AC 97 ms
16,248 KB
testcase_111 AC 119 ms
16,944 KB
testcase_112 AC 40 ms
10,904 KB
testcase_113 AC 96 ms
15,964 KB
testcase_114 AC 55 ms
12,472 KB
testcase_115 AC 19 ms
8,392 KB
testcase_116 AC 66 ms
13,584 KB
testcase_117 AC 41 ms
10,948 KB
testcase_118 AC 149 ms
19,616 KB
testcase_119 AC 80 ms
14,340 KB
testcase_120 AC 132 ms
19,144 KB
testcase_121 AC 34 ms
10,156 KB
testcase_122 AC 67 ms
13,520 KB
testcase_123 AC 4 ms
5,548 KB
testcase_124 AC 218 ms
29,948 KB
testcase_125 AC 213 ms
29,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
template<class T> using prique = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr int mod1e9 = 1000000007;
constexpr int mod998 = 998244353;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; };
int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 };
void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); }
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; }
template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; }

struct fastio {
	fastio() {
		cin.tie(0); cout.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(20);
		cerr << fixed << setprecision(20);
	}
}fastio_;

const int N = ten(5) + 10;
vector<vector<int>> graph(N, vector<int>());
vector<int> par(N);
vector<bool> used(N);
int x, y;

void dfs(int n, int p) {
	used[n] = true;
	par[n] = p;
	for (int i : graph[n]) {
		if (i == p) continue;
		if (used[i]) x = n, y = i;
		else dfs(i, n);
	}
}

int main() {
	int n;
	cin >> n;
	map<P, int> mp;
	rep(i, n) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		graph[u].pb(v);
		graph[v].pb(u);
		mp[{u, v}] = i + 1;
		mp[{v, u}] = i + 1;
	}
	dfs(0, -1);
	vector<int> ans;
	ans.pb(mp[{x, y}]);
	while (x != y) {
		ans.pb(mp[{y, par[y]}]);
		y = par[y];
	}
	cout << ans.size() << '\n';
	for (int i : ans) cout << i << ' ';
	cout << '\n';
}
0