結果

問題 No.1254 補強への架け橋
ユーザー tanimani364tanimani364
提出日時 2021-03-30 15:14:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 3,283 bytes
コンパイル時間 3,004 ms
コンパイル使用メモリ 216,620 KB
実行使用メモリ 26,804 KB
最終ジャッジ日時 2023-08-20 11:52:36
合計ジャッジ時間 21,102 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 3 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 2 ms
4,380 KB
testcase_53 AC 2 ms
4,376 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 2 ms
4,380 KB
testcase_57 AC 2 ms
4,376 KB
testcase_58 AC 2 ms
4,376 KB
testcase_59 AC 1 ms
4,380 KB
testcase_60 AC 2 ms
4,380 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 2 ms
4,376 KB
testcase_63 AC 10 ms
4,596 KB
testcase_64 AC 3 ms
4,376 KB
testcase_65 AC 7 ms
4,380 KB
testcase_66 AC 6 ms
4,376 KB
testcase_67 AC 3 ms
4,376 KB
testcase_68 AC 7 ms
4,380 KB
testcase_69 AC 8 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,376 KB
testcase_74 AC 8 ms
4,376 KB
testcase_75 AC 6 ms
4,380 KB
testcase_76 AC 3 ms
4,380 KB
testcase_77 AC 5 ms
4,376 KB
testcase_78 AC 9 ms
4,640 KB
testcase_79 AC 9 ms
4,644 KB
testcase_80 AC 9 ms
4,392 KB
testcase_81 AC 10 ms
4,524 KB
testcase_82 AC 9 ms
4,496 KB
testcase_83 AC 160 ms
16,692 KB
testcase_84 AC 150 ms
16,376 KB
testcase_85 AC 77 ms
11,136 KB
testcase_86 AC 124 ms
14,680 KB
testcase_87 AC 138 ms
15,656 KB
testcase_88 AC 15 ms
5,384 KB
testcase_89 AC 156 ms
16,588 KB
testcase_90 AC 84 ms
11,744 KB
testcase_91 AC 61 ms
10,032 KB
testcase_92 AC 27 ms
6,700 KB
testcase_93 AC 117 ms
14,176 KB
testcase_94 AC 99 ms
13,200 KB
testcase_95 AC 100 ms
13,376 KB
testcase_96 AC 151 ms
15,920 KB
testcase_97 AC 51 ms
9,036 KB
testcase_98 AC 153 ms
16,176 KB
testcase_99 AC 75 ms
10,924 KB
testcase_100 AC 166 ms
16,796 KB
testcase_101 AC 25 ms
6,540 KB
testcase_102 AC 13 ms
5,016 KB
testcase_103 AC 27 ms
6,796 KB
testcase_104 AC 41 ms
8,260 KB
testcase_105 AC 118 ms
14,172 KB
testcase_106 AC 58 ms
9,512 KB
testcase_107 AC 161 ms
16,540 KB
testcase_108 AC 158 ms
16,024 KB
testcase_109 AC 111 ms
13,740 KB
testcase_110 AC 96 ms
13,112 KB
testcase_111 AC 110 ms
13,704 KB
testcase_112 AC 38 ms
7,792 KB
testcase_113 AC 92 ms
12,464 KB
testcase_114 AC 53 ms
9,412 KB
testcase_115 AC 17 ms
5,684 KB
testcase_116 AC 61 ms
10,392 KB
testcase_117 AC 38 ms
7,980 KB
testcase_118 AC 141 ms
16,000 KB
testcase_119 AC 68 ms
10,888 KB
testcase_120 AC 141 ms
15,196 KB
testcase_121 AC 31 ms
7,272 KB
testcase_122 AC 60 ms
10,132 KB
testcase_123 AC 1 ms
4,380 KB
testcase_124 AC 181 ms
26,740 KB
testcase_125 AC 186 ms
26,804 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 G >
struct LowLink {
  const G &g;
  vector< int > used, ord, low;
  vector< int > articulation;
  vector< pair< int, int > > bridge;
 
  LowLink(const G &g) : g(g) {}
 
  int dfs(int idx, int k, int par) {
    used[idx] = true;
    ord[idx] = k++;
    low[idx] = ord[idx];
    bool is_articulation = false;
    int cnt = 0;
    for(auto &to : g[idx]) {
      if(!used[to]) {
        ++cnt;
        k = dfs(to, k, idx);
        low[idx] = min(low[idx], low[to]);
        is_articulation |= ~par && low[to] >= ord[idx];
        if(ord[idx] < low[to]) bridge.emplace_back(minmax(idx, (int) to));
      } else if(to != par) {
        low[idx] = min(low[idx], ord[to]);
      }
    }
    is_articulation |= par == -1 && cnt > 1;
    if(is_articulation) articulation.push_back(idx);
    return k;
  }
 
  virtual void build() {
    used.assign(g.size(), 0);
    ord.assign(g.size(), 0);
    low.assign(g.size(), 0);
    int k = 0;
    for(int i = 0; i < g.size(); i++) {
      if(!used[i]) k = dfs(i, k, -1);
    }
  }
};

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<vector<vector<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