結果

問題 No.1254 補強への架け橋
ユーザー marurunn11marurunn11
提出日時 2020-10-11 15:39:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 4,359 bytes
コンパイル時間 3,172 ms
コンパイル使用メモリ 193,624 KB
実行使用メモリ 21,360 KB
最終ジャッジ日時 2023-09-27 22:59:04
合計ジャッジ時間 12,377 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 2 ms
4,376 KB
testcase_53 AC 2 ms
4,376 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 1 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,380 KB
testcase_59 AC 1 ms
4,376 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 2 ms
4,380 KB
testcase_62 AC 1 ms
4,376 KB
testcase_63 AC 8 ms
4,380 KB
testcase_64 AC 3 ms
4,376 KB
testcase_65 AC 6 ms
4,376 KB
testcase_66 AC 4 ms
4,380 KB
testcase_67 AC 3 ms
4,376 KB
testcase_68 AC 5 ms
4,380 KB
testcase_69 AC 6 ms
4,376 KB
testcase_70 AC 3 ms
4,376 KB
testcase_71 AC 3 ms
4,380 KB
testcase_72 AC 7 ms
4,376 KB
testcase_73 AC 3 ms
4,380 KB
testcase_74 AC 6 ms
4,376 KB
testcase_75 AC 5 ms
4,376 KB
testcase_76 AC 3 ms
4,376 KB
testcase_77 AC 4 ms
4,380 KB
testcase_78 AC 8 ms
4,376 KB
testcase_79 AC 8 ms
4,380 KB
testcase_80 AC 7 ms
4,376 KB
testcase_81 AC 8 ms
4,376 KB
testcase_82 AC 7 ms
4,384 KB
testcase_83 AC 74 ms
14,336 KB
testcase_84 AC 72 ms
13,968 KB
testcase_85 AC 44 ms
9,968 KB
testcase_86 AC 60 ms
12,628 KB
testcase_87 AC 69 ms
13,272 KB
testcase_88 AC 12 ms
4,712 KB
testcase_89 AC 88 ms
14,232 KB
testcase_90 AC 52 ms
10,148 KB
testcase_91 AC 38 ms
8,892 KB
testcase_92 AC 20 ms
6,188 KB
testcase_93 AC 60 ms
12,084 KB
testcase_94 AC 53 ms
11,240 KB
testcase_95 AC 51 ms
11,240 KB
testcase_96 AC 68 ms
13,584 KB
testcase_97 AC 32 ms
8,136 KB
testcase_98 AC 70 ms
13,936 KB
testcase_99 AC 42 ms
9,704 KB
testcase_100 AC 75 ms
14,332 KB
testcase_101 AC 18 ms
5,716 KB
testcase_102 AC 10 ms
4,896 KB
testcase_103 AC 19 ms
5,940 KB
testcase_104 AC 26 ms
7,208 KB
testcase_105 AC 63 ms
12,112 KB
testcase_106 AC 35 ms
8,312 KB
testcase_107 AC 75 ms
14,136 KB
testcase_108 AC 73 ms
14,396 KB
testcase_109 AC 59 ms
12,000 KB
testcase_110 AC 55 ms
11,296 KB
testcase_111 AC 57 ms
11,884 KB
testcase_112 AC 26 ms
6,936 KB
testcase_113 AC 50 ms
10,940 KB
testcase_114 AC 33 ms
8,448 KB
testcase_115 AC 13 ms
4,912 KB
testcase_116 AC 40 ms
9,340 KB
testcase_117 AC 27 ms
6,992 KB
testcase_118 AC 71 ms
13,668 KB
testcase_119 AC 43 ms
9,620 KB
testcase_120 AC 69 ms
13,320 KB
testcase_121 AC 22 ms
6,452 KB
testcase_122 AC 37 ms
8,828 KB
testcase_123 AC 1 ms
4,380 KB
testcase_124 AC 106 ms
21,360 KB
testcase_125 AC 107 ms
21,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include "bits/stdc++.h"

#ifdef _MSC_VER
#include <intrin.h>  //gcc上ではこれがあると動かない。__popcnt, umul128 等用のincludeファイル。
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#pragma warning(disable : 4996)
#pragma intrinsic(_umul128)
#endif

//#include <atcoder/all>
//using namespace atcoder;

//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/multiprecision/cpp_dec_float.hpp>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int long long
#define double long double
#define LL128 boost::multiprecision::int128_t
#define LL boost::multiprecision::cpp_int
#define LD100 boost::multiprecision::cpp_dec_float_100

#define rep(i, n) for(long long i = 0; i < (n); i++)
#define sqrt(d) pow((ld) (d), 0.50)
#define PII pair<int, int>
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()

const int INF = std::numeric_limits<int>::max() / 2 - 100000000;
const long long INF2 = std::numeric_limits<long long>::max() / 2 - 100000000;
const ld pi = acos(-1);

constexpr int MOD = 1000000007; //1e9 + 7
//constexpr int MOD = 1000000009; //1e9 + 9
//constexpr int MOD = 998244353;  // 7 * 17 * 2^23 + 1




//無向グラフ、メモリ節約版
class Lowlink {
	
private:
	struct edge {
		int to;
		int rev;
		bool seen;
	};

	int N = 0;
	vector<vector<edge> > G;

	vector<bool> seen_v;

	vector<int> ord;
	vector<int> lowlink;

	int root = 0;


	void dfs(int v, int& first_ptr) {
		assert(0 <= v && v < N);
		seen_v[v] = true;

		//行きがけ順
		ord[v] = lowlink[v] = first_ptr++;

		for (int i = 0; i < (int)G[v].size(); i++) {
			int next_v = G[v][i].to;
			if (!seen_v[next_v]) {
				//行先の頂点をまだ見ていない。
				G[v][i].seen = true;
				dfs(next_v, first_ptr);
				lowlink[v] = min(lowlink[v], lowlink[next_v]);
			}
			else if(!G[next_v][G[v][i].rev].seen) {//逆に辿らない。

				//行先の頂点を既に見ている、かつ逆辺を見ていない。v → next_v = G[v][i] は後退辺 (backward edge)
				lowlink[v] = min(lowlink[v], ord[next_v]);
			}
		}

		return;
	}


public:
	Lowlink(int _N) : N(_N), G(_N), seen_v(_N, false), ord(_N, -1), lowlink(_N, -1) {
		
	};


	//辺の追加
	void add_edge(int from, int to) { 
		assert(0 <= from && from < N);
		assert(0 <= to && to < N);
		G[from].push_back(edge{ to, (int)G[to].size(), false });
		G[to].push_back(edge{ from, (int)G[from].size() - 1, false });
	};


	//初期化
	void reset(){
		G.assign(N, vector<edge>());
		seen_v.assign(N, false);
		ord.assign(N, -1);
		lowlink.assign(N, -1);
	}


	//根の変更
	void set_root(int v) {
		root = v;
	}


	void dfs() {
		int first_ptr = 0;
		dfs(root, first_ptr);
		return;
	}


	//そもそも連結であるか確認
	bool is_connected() {
		for(int v = 0; v < N; v++) {
			if (!seen_v[v]) return false;
		}
		return true;
	}


	bool is_bridge(int from, int to) {
		//dfs実行後である確認。
		assert(ord[0] != -1);
		assert(0 <= from && from < N);
		assert(0 <= to && to < N);

		if (ord[from] > ord[to]) swap(from, to);

		if (ord[from] < lowlink[to]) return true;
		else return false;
	}


	bool is_articulation(int v) {
		//dfs実行後である確認。
		assert(ord[0] != -1);
		assert(0 <= v && v < N);

		if (v == root) {
			int cnt = 0;
			rep(i, (int)G[v].size()) {
				if (G[v][i].seen) cnt++;
			}

			return (cnt != 1 && cnt != 0);
			//cnt != 1 だけだと、頂点が1つだけの連結グラフでバグる。(cnt == 0 で、頂点 0 は連結点でない)
		}
		else {
			rep(i, (int)G[v].size()) {
				int child = G[v][i].to;
				if (G[v][i].seen) {
					if (lowlink[child] >= ord[v]) return true;
				}
			}
			return false;
		}

	}
};




signed main() {
	int N; cin >> N;
	vector<int> a(N), b(N);
	rep(i, N) {
		cin >> a.at(i) >> b.at(i);
		a[i]--; b[i]--;
	}

	Lowlink G(N);
	rep(i, N) {
		G.add_edge(a[i], b[i]);
		//G.add_edge(b[i], a[i]);
	}
	G.dfs();

	vector<int> res;
	rep(i, N) {
		//if (!G.is_bridge(a[i], b[i]) && !G.is_bridge(b[i], a[i])) res.push_back(i + 1);
		if (!G.is_bridge(a[i], b[i])) res.push_back(i + 1);
	}

	cout << res.size() << endl;
	rep(i, (int)res.size()) {
		if (i != res.size() - 1) cout << res[i] << " ";
		else cout << res[i] << endl;
	}
}
0