結果

問題 No.1254 補強への架け橋
ユーザー SHIJOUSHIJOU
提出日時 2020-10-16 22:12:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 2,878 bytes
コンパイル時間 2,182 ms
コンパイル使用メモリ 212,928 KB
実行使用メモリ 25,476 KB
最終ジャッジ日時 2023-09-28 03:26:15
合計ジャッジ時間 12,721 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 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 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 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,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 1 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 1 ms
4,380 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 1 ms
4,380 KB
testcase_59 AC 1 ms
4,380 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 2 ms
4,380 KB
testcase_62 AC 2 ms
4,376 KB
testcase_63 AC 4 ms
4,380 KB
testcase_64 AC 2 ms
4,380 KB
testcase_65 AC 3 ms
4,376 KB
testcase_66 AC 3 ms
4,376 KB
testcase_67 AC 3 ms
4,376 KB
testcase_68 AC 3 ms
4,380 KB
testcase_69 AC 3 ms
4,380 KB
testcase_70 AC 3 ms
4,376 KB
testcase_71 AC 2 ms
4,380 KB
testcase_72 AC 3 ms
4,380 KB
testcase_73 AC 2 ms
4,376 KB
testcase_74 AC 4 ms
4,376 KB
testcase_75 AC 3 ms
4,376 KB
testcase_76 AC 2 ms
4,376 KB
testcase_77 AC 3 ms
4,380 KB
testcase_78 AC 4 ms
4,376 KB
testcase_79 AC 4 ms
4,376 KB
testcase_80 AC 3 ms
4,376 KB
testcase_81 AC 5 ms
4,380 KB
testcase_82 AC 4 ms
4,376 KB
testcase_83 AC 39 ms
11,008 KB
testcase_84 AC 36 ms
10,744 KB
testcase_85 AC 22 ms
7,960 KB
testcase_86 AC 31 ms
9,620 KB
testcase_87 AC 37 ms
10,484 KB
testcase_88 AC 6 ms
4,376 KB
testcase_89 AC 39 ms
10,936 KB
testcase_90 AC 27 ms
8,116 KB
testcase_91 AC 20 ms
7,036 KB
testcase_92 AC 11 ms
5,136 KB
testcase_93 AC 33 ms
9,440 KB
testcase_94 AC 33 ms
8,832 KB
testcase_95 AC 29 ms
8,756 KB
testcase_96 AC 36 ms
10,380 KB
testcase_97 AC 17 ms
6,456 KB
testcase_98 AC 36 ms
10,700 KB
testcase_99 AC 22 ms
7,788 KB
testcase_100 AC 39 ms
11,156 KB
testcase_101 AC 10 ms
4,928 KB
testcase_102 AC 6 ms
4,380 KB
testcase_103 AC 10 ms
5,200 KB
testcase_104 AC 13 ms
5,892 KB
testcase_105 AC 30 ms
9,368 KB
testcase_106 AC 17 ms
6,704 KB
testcase_107 AC 38 ms
10,884 KB
testcase_108 AC 38 ms
10,668 KB
testcase_109 AC 31 ms
9,444 KB
testcase_110 AC 27 ms
8,532 KB
testcase_111 AC 28 ms
9,104 KB
testcase_112 AC 13 ms
6,000 KB
testcase_113 AC 27 ms
8,540 KB
testcase_114 AC 17 ms
6,696 KB
testcase_115 AC 7 ms
4,384 KB
testcase_116 AC 21 ms
7,192 KB
testcase_117 AC 13 ms
6,012 KB
testcase_118 AC 35 ms
10,356 KB
testcase_119 AC 21 ms
7,524 KB
testcase_120 AC 35 ms
10,360 KB
testcase_121 AC 12 ms
5,356 KB
testcase_122 AC 19 ms
7,252 KB
testcase_123 AC 1 ms
4,376 KB
testcase_124 AC 57 ms
25,172 KB
testcase_125 AC 57 ms
25,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

struct TECC {
	struct Edge {
		int to, rev;
		Edge() {}
		Edge(int t, int r):to(t), rev(r) {}
	};
	int n;
	vector<vector<Edge>> G;
	TECC(int n_) : n(n_), G(n_) {}
	void add(int u, int v) {
		G[u].emplace_back(v, int(G[v].size()));
		G[v].emplace_back(u, int(G[u].size())-1);
	}
	pair<int, vector<int>> tecc_ids() {
		int now_ord = 0, group_num = 0;
		vector<int> used, low(n), ord(n, -1), ids(n);
		used.reserve(n);
		auto dfs = [&](auto self, int v)->void {
			low[v] = ord[v] = now_ord++;
			used.push_back(v);
			for(Edge &e:G[v]) if(e.rev != -1) {
				int to = e.to;
				G[to][e.rev].rev = -1;
				e.rev = -1;
				if(ord[to] == -1) {
					self(self, to);
					low[v] = min(low[v], low[to]);
				}
				else {
					low[v] = min(low[v], ord[to]);
				}
			}
			if(low[v] == ord[v]) {
				int u;
				do {
					u = used.back();
					used.pop_back();
					ord[u] = n;
					ids[u] = group_num;
				} while(u != v);
				group_num++;
			}
		};
		for(int i = 0; i < n; i++) {
			if(ord[i] == -1) dfs(dfs, i);
		}
		for(int &x:ids) {
			x = group_num - 1 - x;
		}
		return {group_num, ids};
	}
	vector<vector<int>> tecc() {
		pair<int, vector<int>> ids = tecc_ids();
		int group_num = ids.first;
		vector<int> counts(group_num);
		for(int x:ids.second) counts[x]++;
		vector<vector<int>> groups(group_num);
		for(int i = 0; i < group_num; i++) {
			groups[i].reserve(counts[i]);
		}
		for(int i = 0; i < n; i++) {
			groups[ids.second[i]].push_back(i);
		}
		return groups;
	}
};

//head



int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	TECC tecc(n);
	vector<P> edges(n);
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		edges[i] = {--a, --b};
		tecc.add(a, b);
	}
	vi ans;
	ans.reserve(n);
	vi info = tecc.tecc_ids().second;
	rep(i, n) {
		auto [u, v] = edges[i];
		if(info[u] == info[v]) ans.push_back(i+1);
	}
	cout << size(ans) << endl;
	for(int x:ans) cout << x << ' ';
	cout << endl;
}
0