結果

問題 No.1254 補強への架け橋
ユーザー tanimani364tanimani364
提出日時 2021-03-30 16:45:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 3,019 bytes
コンパイル時間 5,163 ms
コンパイル使用メモリ 217,392 KB
実行使用メモリ 35,140 KB
最終ジャッジ日時 2023-08-20 13:24:28
合計ジャッジ時間 18,796 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 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,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,384 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,384 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 3 ms
4,376 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 3 ms
4,376 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 3 ms
4,380 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 2 ms
4,380 KB
testcase_57 AC 2 ms
4,376 KB
testcase_58 AC 2 ms
4,380 KB
testcase_59 AC 2 ms
4,376 KB
testcase_60 AC 2 ms
4,380 KB
testcase_61 AC 3 ms
4,376 KB
testcase_62 AC 2 ms
4,376 KB
testcase_63 AC 12 ms
5,236 KB
testcase_64 AC 4 ms
4,376 KB
testcase_65 AC 8 ms
4,544 KB
testcase_66 AC 7 ms
4,444 KB
testcase_67 AC 3 ms
4,376 KB
testcase_68 AC 7 ms
4,388 KB
testcase_69 AC 9 ms
4,632 KB
testcase_70 AC 4 ms
4,380 KB
testcase_71 AC 4 ms
4,380 KB
testcase_72 AC 9 ms
4,668 KB
testcase_73 AC 4 ms
4,380 KB
testcase_74 AC 9 ms
4,576 KB
testcase_75 AC 7 ms
4,444 KB
testcase_76 AC 3 ms
4,380 KB
testcase_77 AC 6 ms
4,380 KB
testcase_78 AC 11 ms
4,908 KB
testcase_79 AC 11 ms
4,992 KB
testcase_80 AC 10 ms
4,752 KB
testcase_81 AC 11 ms
5,040 KB
testcase_82 AC 11 ms
4,948 KB
testcase_83 AC 189 ms
21,468 KB
testcase_84 AC 184 ms
20,652 KB
testcase_85 AC 97 ms
14,128 KB
testcase_86 AC 147 ms
18,828 KB
testcase_87 AC 161 ms
19,924 KB
testcase_88 AC 17 ms
5,968 KB
testcase_89 AC 184 ms
21,340 KB
testcase_90 AC 99 ms
14,680 KB
testcase_91 AC 76 ms
12,488 KB
testcase_92 AC 33 ms
8,028 KB
testcase_93 AC 137 ms
17,936 KB
testcase_94 AC 118 ms
16,832 KB
testcase_95 AC 121 ms
16,640 KB
testcase_96 AC 172 ms
20,312 KB
testcase_97 AC 60 ms
11,236 KB
testcase_98 AC 169 ms
20,660 KB
testcase_99 AC 87 ms
13,836 KB
testcase_100 AC 185 ms
21,684 KB
testcase_101 AC 28 ms
7,620 KB
testcase_102 AC 15 ms
5,592 KB
testcase_103 AC 31 ms
8,112 KB
testcase_104 AC 50 ms
10,176 KB
testcase_105 AC 135 ms
18,148 KB
testcase_106 AC 68 ms
11,844 KB
testcase_107 AC 179 ms
21,296 KB
testcase_108 AC 180 ms
20,924 KB
testcase_109 AC 133 ms
17,572 KB
testcase_110 AC 116 ms
16,640 KB
testcase_111 AC 120 ms
17,372 KB
testcase_112 AC 43 ms
9,324 KB
testcase_113 AC 112 ms
15,800 KB
testcase_114 AC 63 ms
11,556 KB
testcase_115 AC 21 ms
6,176 KB
testcase_116 AC 81 ms
13,016 KB
testcase_117 AC 46 ms
9,740 KB
testcase_118 AC 178 ms
20,448 KB
testcase_119 AC 84 ms
13,896 KB
testcase_120 AC 160 ms
19,812 KB
testcase_121 AC 37 ms
8,672 KB
testcase_122 AC 76 ms
12,892 KB
testcase_123 AC 2 ms
4,380 KB
testcase_124 AC 188 ms
35,140 KB
testcase_125 AC 197 ms
34,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
#define fi first
#define se second
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll mod_998244353 = 998244353;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

//using lll=boost::multiprecision::cpp_int;
//using Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1024>>;//仮数部が1024桁
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

template <typename T>
T mypow(T x, T n, const T &p = -1)
{ //x^nをmodで割った余り

	if (p != -1)
	{
		x %= p;
	}
	T ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

using namespace std;
//using namespace atcoder;


template<typename T>
struct LowLink{
	vector<vector<T>> g;
	vector<int>ord,low;
	vector<int>articulation;//関節点
	vector<pair<int,int>>bridge;//橋
	LowLink(const vector<vector<T>> &_g):g(_g){
		ord.assign(g.size(),-1);
		low.assign(g.size(),0);
	}
	void dfs(int v=0,int par=-1,int cnt=0){
		ord[v]=cnt++;
		low[v]=ord[v];
		bool is_arp=false;
		for(auto x:g[v]){
			if(ord[x]==-1){
				dfs(x,v,cnt);
				low[v]=min(low[v],low[x]);
				if(ord[v]<low[x]){
					int from=min(v,x);
					int to=max(v,x);
					bridge.emplace_back(from,to);
				}
				if(ord[v]<=low[x]){
					is_arp=true;
				}
			}else if(x!=par){//x=parを許容すると橋のときに壊れる
				low[v]=min(ord[x],low[v]);
			}
		}
		if(is_arp){
			articulation.emplace_back(v);
		}
	}
	void build(){
		dfs();
	}
};
using P=pair<int,int>;
void solve()
{	
	int n;
	cin>>n;
	vector<vector<int>>g(n);
	map<pair<int,int>,int>mp;
	rep(i,n){
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].eb(b);
		g[b].eb(a);
		if(a>b)swap(a,b);
		mp[P{a,b}]=i+1;
	}
	LowLink<int>lowlink(g);
	lowlink.build();
	for(auto e:lowlink.bridge){
		if(e.first>e.second)swap(e.fi,e.se);
		mp.erase(P(e.first,e.second));
	}
	int ans=mp.size();
	cout<<ans<<"\n";
	for(auto itr=mp.begin();itr!=mp.end();++itr){
		if(itr!=mp.begin())cout<<" ";
		cout<<itr->second;
	}
	cout<<"\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
0