結果

問題 No.1254 補強への架け橋
ユーザー leaf_1415leaf_1415
提出日時 2020-10-09 21:55:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 1,869 bytes
コンパイル時間 1,178 ms
コンパイル使用メモリ 90,724 KB
実行使用メモリ 23,140 KB
最終ジャッジ日時 2023-09-27 16:44:05
合計ジャッジ時間 13,366 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,836 KB
testcase_01 AC 3 ms
5,832 KB
testcase_02 AC 3 ms
5,836 KB
testcase_03 AC 3 ms
5,628 KB
testcase_04 AC 3 ms
5,792 KB
testcase_05 AC 3 ms
5,796 KB
testcase_06 AC 3 ms
5,632 KB
testcase_07 AC 3 ms
5,756 KB
testcase_08 AC 4 ms
5,812 KB
testcase_09 AC 3 ms
5,792 KB
testcase_10 AC 3 ms
5,628 KB
testcase_11 AC 2 ms
5,736 KB
testcase_12 AC 3 ms
5,744 KB
testcase_13 AC 4 ms
5,692 KB
testcase_14 AC 4 ms
5,844 KB
testcase_15 AC 5 ms
5,832 KB
testcase_16 AC 3 ms
5,932 KB
testcase_17 AC 3 ms
5,800 KB
testcase_18 AC 3 ms
5,800 KB
testcase_19 AC 3 ms
5,652 KB
testcase_20 AC 3 ms
5,644 KB
testcase_21 AC 3 ms
5,932 KB
testcase_22 AC 3 ms
5,688 KB
testcase_23 AC 3 ms
5,836 KB
testcase_24 AC 3 ms
5,748 KB
testcase_25 AC 3 ms
5,816 KB
testcase_26 AC 3 ms
5,828 KB
testcase_27 AC 4 ms
5,740 KB
testcase_28 AC 3 ms
5,824 KB
testcase_29 AC 3 ms
5,808 KB
testcase_30 AC 3 ms
5,752 KB
testcase_31 AC 3 ms
5,652 KB
testcase_32 AC 3 ms
5,748 KB
testcase_33 AC 3 ms
5,652 KB
testcase_34 AC 3 ms
5,732 KB
testcase_35 AC 3 ms
5,952 KB
testcase_36 AC 3 ms
5,968 KB
testcase_37 AC 3 ms
5,764 KB
testcase_38 AC 3 ms
5,900 KB
testcase_39 AC 3 ms
5,748 KB
testcase_40 AC 3 ms
5,800 KB
testcase_41 AC 4 ms
5,828 KB
testcase_42 AC 3 ms
5,728 KB
testcase_43 AC 3 ms
5,748 KB
testcase_44 AC 3 ms
5,780 KB
testcase_45 AC 3 ms
5,784 KB
testcase_46 AC 4 ms
5,944 KB
testcase_47 AC 4 ms
5,700 KB
testcase_48 AC 4 ms
5,876 KB
testcase_49 AC 3 ms
5,824 KB
testcase_50 AC 4 ms
5,992 KB
testcase_51 AC 4 ms
5,748 KB
testcase_52 AC 3 ms
6,016 KB
testcase_53 AC 4 ms
5,864 KB
testcase_54 AC 4 ms
5,760 KB
testcase_55 AC 4 ms
5,864 KB
testcase_56 AC 3 ms
5,716 KB
testcase_57 AC 3 ms
5,824 KB
testcase_58 AC 3 ms
5,852 KB
testcase_59 AC 3 ms
5,764 KB
testcase_60 AC 4 ms
5,688 KB
testcase_61 AC 4 ms
5,988 KB
testcase_62 AC 4 ms
5,820 KB
testcase_63 AC 10 ms
6,804 KB
testcase_64 AC 4 ms
6,208 KB
testcase_65 AC 8 ms
6,432 KB
testcase_66 AC 7 ms
6,352 KB
testcase_67 AC 5 ms
5,900 KB
testcase_68 AC 7 ms
6,448 KB
testcase_69 AC 9 ms
6,632 KB
testcase_70 AC 5 ms
6,304 KB
testcase_71 AC 5 ms
6,188 KB
testcase_72 AC 9 ms
6,532 KB
testcase_73 AC 5 ms
6,140 KB
testcase_74 AC 9 ms
6,656 KB
testcase_75 AC 7 ms
6,624 KB
testcase_76 AC 4 ms
5,804 KB
testcase_77 AC 6 ms
6,380 KB
testcase_78 AC 13 ms
6,856 KB
testcase_79 AC 11 ms
6,708 KB
testcase_80 AC 10 ms
6,744 KB
testcase_81 AC 10 ms
6,864 KB
testcase_82 AC 10 ms
6,904 KB
testcase_83 AC 143 ms
17,124 KB
testcase_84 AC 140 ms
16,984 KB
testcase_85 AC 68 ms
12,236 KB
testcase_86 AC 100 ms
15,524 KB
testcase_87 AC 119 ms
16,416 KB
testcase_88 AC 15 ms
7,388 KB
testcase_89 AC 122 ms
17,100 KB
testcase_90 AC 67 ms
12,648 KB
testcase_91 AC 52 ms
11,352 KB
testcase_92 AC 26 ms
8,896 KB
testcase_93 AC 100 ms
15,244 KB
testcase_94 AC 81 ms
14,572 KB
testcase_95 AC 78 ms
14,492 KB
testcase_96 AC 109 ms
16,588 KB
testcase_97 AC 41 ms
10,552 KB
testcase_98 AC 114 ms
16,764 KB
testcase_99 AC 62 ms
12,128 KB
testcase_100 AC 116 ms
17,296 KB
testcase_101 AC 22 ms
8,528 KB
testcase_102 AC 13 ms
7,092 KB
testcase_103 AC 25 ms
8,624 KB
testcase_104 AC 35 ms
9,944 KB
testcase_105 AC 85 ms
15,300 KB
testcase_106 AC 45 ms
11,040 KB
testcase_107 AC 111 ms
16,968 KB
testcase_108 AC 108 ms
17,124 KB
testcase_109 AC 85 ms
15,016 KB
testcase_110 AC 73 ms
14,424 KB
testcase_111 AC 79 ms
14,824 KB
testcase_112 AC 32 ms
9,460 KB
testcase_113 AC 70 ms
13,464 KB
testcase_114 AC 46 ms
11,000 KB
testcase_115 AC 17 ms
7,388 KB
testcase_116 AC 53 ms
11,488 KB
testcase_117 AC 34 ms
9,964 KB
testcase_118 AC 104 ms
16,420 KB
testcase_119 AC 56 ms
12,072 KB
testcase_120 AC 102 ms
16,192 KB
testcase_121 AC 30 ms
9,024 KB
testcase_122 AC 50 ms
11,564 KB
testcase_123 AC 4 ms
5,632 KB
testcase_124 AC 116 ms
23,136 KB
testcase_125 AC 115 ms
23,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint n;
map<P, llint> mp;
bool used[100005];

vector<int> G[100005];
vector<P> bridge;
int pre[100005], low[100005];

int id = 1;
int bridge_dfs(int v, int prev)
{
	pre[v] = id++;
	int ret = pre[v];
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == prev) continue;
		if(pre[G[v][i]]) ret = min(ret, pre[G[v][i]]);
		else ret = min(ret, bridge_dfs(G[v][i], v));
	}
	return low[v] = ret;
}

//find the unordered pairs{start, end} of all bridges.
void findBridge(int v = 1)
{
	bridge_dfs(v, -1);
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < G[i].size(); j++){
			if(pre[i] < pre[G[i][j]] && low[G[i][j]] > pre[i]) bridge.push_back(make_pair(i, G[i][j]));
		}
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	llint u, v;
	for(int i = 1; i <= n; i++){
		cin >> u >> v;
		if(u > v) swap(u, v);
		mp[P(u, v)] = i;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	findBridge();
	
	vector<llint> ans;
	for(int i = 0; i < bridge.size(); i++){
		u = bridge[i].first, v = bridge[i].second;
		if(u > v) swap(u, v);
		used[mp[P(u, v)]] = true;
	}
	for(int i = 1; i <= n; i++) if(!used[i]) ans.push_back(i);
	
	cout << ans.size() << endl;
	for(int i = 0; i < ans.size(); i++) cout << ans[i] << " "; cout << endl;
	
	return 0;
}
0