結果

問題 No.1254 補強への架け橋
ユーザー kenta255kenta255
提出日時 2020-10-10 11:08:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 2,563 bytes
コンパイル時間 2,349 ms
コンパイル使用メモリ 218,652 KB
実行使用メモリ 21,044 KB
最終ジャッジ日時 2023-09-27 21:12:05
合計ジャッジ時間 15,010 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,384 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 3 ms
4,376 KB
testcase_53 AC 3 ms
4,376 KB
testcase_54 AC 3 ms
4,384 KB
testcase_55 AC 3 ms
4,380 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 2 ms
4,376 KB
testcase_58 AC 2 ms
4,376 KB
testcase_59 AC 1 ms
4,376 KB
testcase_60 AC 2 ms
4,380 KB
testcase_61 AC 3 ms
4,376 KB
testcase_62 AC 1 ms
4,376 KB
testcase_63 AC 13 ms
4,376 KB
testcase_64 AC 4 ms
4,376 KB
testcase_65 AC 8 ms
4,376 KB
testcase_66 AC 7 ms
4,380 KB
testcase_67 AC 3 ms
4,380 KB
testcase_68 AC 7 ms
4,376 KB
testcase_69 AC 9 ms
4,380 KB
testcase_70 AC 5 ms
4,376 KB
testcase_71 AC 4 ms
4,376 KB
testcase_72 AC 9 ms
4,380 KB
testcase_73 AC 4 ms
4,380 KB
testcase_74 AC 9 ms
4,380 KB
testcase_75 AC 7 ms
4,380 KB
testcase_76 AC 3 ms
4,380 KB
testcase_77 AC 6 ms
4,376 KB
testcase_78 AC 11 ms
4,376 KB
testcase_79 AC 12 ms
4,376 KB
testcase_80 AC 10 ms
4,408 KB
testcase_81 AC 12 ms
4,380 KB
testcase_82 AC 11 ms
4,380 KB
testcase_83 AC 143 ms
15,268 KB
testcase_84 AC 135 ms
14,812 KB
testcase_85 AC 85 ms
10,604 KB
testcase_86 AC 117 ms
13,316 KB
testcase_87 AC 126 ms
14,292 KB
testcase_88 AC 17 ms
4,852 KB
testcase_89 AC 138 ms
15,216 KB
testcase_90 AC 82 ms
10,916 KB
testcase_91 AC 65 ms
9,384 KB
testcase_92 AC 34 ms
6,504 KB
testcase_93 AC 112 ms
12,744 KB
testcase_94 AC 97 ms
12,040 KB
testcase_95 AC 97 ms
11,840 KB
testcase_96 AC 129 ms
14,500 KB
testcase_97 AC 56 ms
8,228 KB
testcase_98 AC 135 ms
14,936 KB
testcase_99 AC 75 ms
10,120 KB
testcase_100 AC 152 ms
15,588 KB
testcase_101 AC 29 ms
5,980 KB
testcase_102 AC 15 ms
4,680 KB
testcase_103 AC 32 ms
6,392 KB
testcase_104 AC 45 ms
7,544 KB
testcase_105 AC 112 ms
12,712 KB
testcase_106 AC 62 ms
8,896 KB
testcase_107 AC 140 ms
15,096 KB
testcase_108 AC 141 ms
14,740 KB
testcase_109 AC 105 ms
12,772 KB
testcase_110 AC 93 ms
11,796 KB
testcase_111 AC 108 ms
12,316 KB
testcase_112 AC 43 ms
7,148 KB
testcase_113 AC 90 ms
11,396 KB
testcase_114 AC 55 ms
8,868 KB
testcase_115 AC 19 ms
5,072 KB
testcase_116 AC 67 ms
9,380 KB
testcase_117 AC 43 ms
7,468 KB
testcase_118 AC 134 ms
14,400 KB
testcase_119 AC 75 ms
10,088 KB
testcase_120 AC 129 ms
14,088 KB
testcase_121 AC 35 ms
6,772 KB
testcase_122 AC 71 ms
9,360 KB
testcase_123 AC 2 ms
4,380 KB
testcase_124 AC 118 ms
20,868 KB
testcase_125 AC 115 ms
21,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}


struct Articulation_point_and_Bridge{
int V,E=0;
vector< vector<int> > G;
vector<int> ord,low;
vector<bool> vis;
vector< pair<int, int> > bridge;
vector<int> articulation;
Articulation_point_and_Bridge(int V_){
	V=V_;
	G.resize(V);
	ord.resize(V,0);
	low.resize(V,0);
	vis.resize(V,false);
}
void dfs(int v, int p, int &k){
	vis[v] = true;
	ord[v] = k++;
	low[v] = ord[v];
	bool isArticulation = false;
	int ct = 0;
	for (int i = 0; i < G[v].size(); i++){
		if (!vis[G[v][i]]){
			ct++;
			dfs(G[v][i], v, k);
			low[v] = min(low[v], low[G[v][i]]);
			if (~p && ord[v] <= low[G[v][i]]) isArticulation = true;
			if (ord[v] < low[G[v][i]]) bridge.push_back(make_pair(min(v, G[v][i]), max(v, G[v][i])));
		}
		else if (G[v][i] != p){
			low[v] = min(low[v], ord[G[v][i]]);
		}
	}
	
	if (p == -1 && ct > 1) isArticulation = true;
	if (isArticulation) articulation.push_back(v);
}
void add_edge(int v1,int v2){
	G[v1].push_back(v2);
	G[v2].push_back(v1);
	E++;
}
void calc(){
	int k=0;
	for(int i=0;i<V;i++){
		if(!vis[i])dfs(i,-1,k);
	}
	//sort(bridge.begin(), bridge.end());
	//sort(articulation.begin(), articulation.end());
}
};


int main(){

	ll N;
	cin >> N;

	Articulation_point_and_Bridge g(N);
	vector<pair<int,int>> all_b;
	FOR(i,0,N){
		ll a,b;
		cin >> a >> b;
		if(a>b)swap(a,b);
		g.add_edge(a-1,b-1);
		all_b.push_back({a-1,b-1});
	}

	g.calc();
	set<pair<int,int>> br;
	FOR(i,0,g.bridge.size()){
		br.insert(g.bridge[i]);
	}

	cout << N-g.bridge.size() << endl;
	bool s = false;
	FOR(i,0,N){
		if(not br.count(all_b[i])){
			if(s)cout << " ";
			cout << i+1;
			s = true;
		}
	}

}

0