結果

問題 No.1254 補強への架け橋
ユーザー hamamuhamamu
提出日時 2020-10-09 22:26:14
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 331 ms / 2,000 ms
コード長 5,348 bytes
コンパイル時間 2,424 ms
コンパイル使用メモリ 211,672 KB
実行使用メモリ 30,356 KB
最終ジャッジ日時 2023-09-27 18:11:28
合計ジャッジ時間 17,645 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 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,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 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,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,380 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 1 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 3 ms
4,380 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 2 ms
4,380 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 2 ms
4,376 KB
testcase_56 AC 2 ms
4,380 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 2 ms
4,376 KB
testcase_59 AC 2 ms
4,376 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 2 ms
4,380 KB
testcase_63 AC 12 ms
5,124 KB
testcase_64 AC 4 ms
4,380 KB
testcase_65 AC 8 ms
4,728 KB
testcase_66 AC 7 ms
4,408 KB
testcase_67 AC 4 ms
4,380 KB
testcase_68 AC 7 ms
4,608 KB
testcase_69 AC 9 ms
4,612 KB
testcase_70 AC 4 ms
4,380 KB
testcase_71 AC 4 ms
4,380 KB
testcase_72 AC 9 ms
4,820 KB
testcase_73 AC 4 ms
4,376 KB
testcase_74 AC 8 ms
4,532 KB
testcase_75 AC 7 ms
4,520 KB
testcase_76 AC 2 ms
4,376 KB
testcase_77 AC 6 ms
4,404 KB
testcase_78 AC 12 ms
4,868 KB
testcase_79 AC 12 ms
4,920 KB
testcase_80 AC 10 ms
4,708 KB
testcase_81 AC 12 ms
4,932 KB
testcase_82 AC 12 ms
4,952 KB
testcase_83 AC 219 ms
21,332 KB
testcase_84 AC 213 ms
20,760 KB
testcase_85 AC 109 ms
14,216 KB
testcase_86 AC 173 ms
18,400 KB
testcase_87 AC 182 ms
19,592 KB
testcase_88 AC 19 ms
5,916 KB
testcase_89 AC 207 ms
21,072 KB
testcase_90 AC 107 ms
14,740 KB
testcase_91 AC 88 ms
12,360 KB
testcase_92 AC 33 ms
7,984 KB
testcase_93 AC 155 ms
17,556 KB
testcase_94 AC 132 ms
16,448 KB
testcase_95 AC 143 ms
16,320 KB
testcase_96 AC 197 ms
20,284 KB
testcase_97 AC 70 ms
10,908 KB
testcase_98 AC 204 ms
20,368 KB
testcase_99 AC 104 ms
13,672 KB
testcase_100 AC 228 ms
21,476 KB
testcase_101 AC 32 ms
7,460 KB
testcase_102 AC 16 ms
5,440 KB
testcase_103 AC 36 ms
8,128 KB
testcase_104 AC 53 ms
9,592 KB
testcase_105 AC 166 ms
17,524 KB
testcase_106 AC 74 ms
11,696 KB
testcase_107 AC 218 ms
21,072 KB
testcase_108 AC 209 ms
20,684 KB
testcase_109 AC 163 ms
17,456 KB
testcase_110 AC 133 ms
15,924 KB
testcase_111 AC 172 ms
17,044 KB
testcase_112 AC 54 ms
9,536 KB
testcase_113 AC 136 ms
15,648 KB
testcase_114 AC 87 ms
11,560 KB
testcase_115 AC 23 ms
5,996 KB
testcase_116 AC 94 ms
12,816 KB
testcase_117 AC 50 ms
9,552 KB
testcase_118 AC 201 ms
19,960 KB
testcase_119 AC 108 ms
13,624 KB
testcase_120 AC 190 ms
19,476 KB
testcase_121 AC 43 ms
8,668 KB
testcase_122 AC 86 ms
12,512 KB
testcase_123 AC 1 ms
4,376 KB
testcase_124 AC 330 ms
30,356 KB
testcase_125 AC 331 ms
30,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


#include "bits/stdc++.h"
using namespace std;
using     ll=long long;
using    vll=vector<   ll>;
using   vvll=vector<  vll>;
using  vvvll=vector< vvll>;
using vvvvll=vector<vvvll>;
using     dd=double;
using    vdd=vector<   dd>;
using   vvdd=vector<  vdd>;
using pll=pair<ll,ll>; using tll=tuple<ll,ll,ll>; using qll=tuple<ll,ll,ll,ll>;

constexpr ll INF = 1LL << 60;
struct Fast{ Fast(){ cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(numeric_limits<double>::max_digits10); } } fast;
#define REPS(i, S, E) for (ll i = (S); i <= (E); i++)
#define REP(i, N) REPS(i, 0, (N)-1)
#define DEPS(i, S, E) for (ll i = (E); i >= (S); i--)
#define DEP(i, N) DEPS(i, 0, (N)-1)
#define rep(i, S, E)  for (ll i = (S); i <= (E); i++)
#define dep(i, E, S)  for (ll i = (E); i >= (S); i--)
#define each(e, v) for (auto&& e : v)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; }
template<class T> inline T MaxE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmax(m,v[i]); return m; }
template<class T> inline T MinE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmin(m,v[i]); return m; }
template<class T> inline T MaxE(vector<T> &v) { return MaxE(v,0,(ll)v.size()-1); }
template<class T> inline T MinE(vector<T> &v) { return MinE(v,0,(ll)v.size()-1); }
template<class T> inline T Sum(vector<T> &v,ll S,ll E){ T s=T(); rep(i,S,E)s+=v[i]; return s; }
template<class T> inline T Sum(vector<T> &v) { return Sum(v,0,v.size()-1); }
template<class T> inline ll sz(T &v){ return (ll)v.size(); }
inline ll CEIL(ll a,ll b){ return (a<0) ? -(-a/b) : (a+b-1)/b; }
inline ll FLOOR(ll a,ll b){ return -CEIL(-a,b); }

//vector用テンプレート
template<class T> inline vector<T>& operator+=(vector<T> &a,const vector<T> &b){ for (ll i=0; i<(ll)a.size(); i++) a[i]+=b[i];  return a; }
template<class T> inline vector<T>& operator-=(vector<T> &a,const vector<T> &b){ for (ll i=0; i<(ll)a.size(); i++) a[i]-=b[i];  return a; }
template<class T> inline vector<T>& operator*=(vector<T> &a,const vector<T> &b){ for (ll i=0; i<(ll)a.size(); i++) a[i]*=b[i];  return a; }
template<class T> inline vector<T>& operator/=(vector<T> &a,const vector<T> &b){ for (ll i=0; i<(ll)a.size(); i++) a[i]/=b[i];  return a; }
template<class T> inline vector<T>& operator%=(vector<T> &a,const vector<T> &b){ for (ll i=0; i<(ll)a.size(); i++) a[i]%=b[i];  return a; }
template<class T,class S> inline vector<T>& operator+=(vector<T> &a,S b){ for (T &e: a) e+=b;  return a; }
template<class T,class S> inline vector<T>& operator-=(vector<T> &a,S b){ for (T &e: a) e-=b;  return a; }
template<class T,class S> inline vector<T>& operator*=(vector<T> &a,S b){ for (T &e: a) e*=b;  return a; }
template<class T,class S> inline vector<T>& operator/=(vector<T> &a,S b){ for (T &e: a) e/=b;  return a; }
template<class T,class S> inline vector<T>& operator%=(vector<T> &a,S b){ for (T &e: a) e%=b;  return a; }
template<class T,class S> inline vector<T> operator+(const vector<T> &a,S b){ vector<T> c=a; return c+=b; }
template<class T,class S> inline vector<T> operator-(const vector<T> &a,S b){ vector<T> c=a; return c-=b; }
template<class T,class S> inline vector<T> operator*(const vector<T> &a,S b){ vector<T> c=a; return c*=b; }
template<class T,class S> inline vector<T> operator/(const vector<T> &a,S b){ vector<T> c=a; return c/=b; }
template<class T,class S> inline vector<T> operator%(const vector<T> &a,S b){ vector<T> c=a; return c%=b; }
template<class T,class S> inline vector<T> operator-(S b,const vector<T> &a){ vector<T> c=-a; return c+=b; }
template<class T> inline vector<T> operator-(const vector<T> &a){ vector<T> c=a; return c*=(-1); }
template<class T> inline ostream &operator<<(ostream &os,const vector<T> &a){ for (ll i=0; i<(ll)a.size(); i++) os<<(i>0?" ":"")<<a[i];  return os; }


#if 0
#include <atcoder/all>
using namespace atcoder;
#endif

vvll to;
vll seen; //seen[v]=1:訪れた 0:訪れていない
vll cycle;
map<pll,ll> idxes;


vvll cinGraph(ll nodeNum,ll edgeNum,bool isDirected){//無向false、有向true
	vvll to(nodeNum);
	rep(i,0,edgeNum-1){
		ll v,u; cin >> v >> u;
		v--; u--;
		to[v].push_back(u);
		if (!isDirected) to[u].push_back(v);
		idxes[pll(v,u)]=i+1;
		idxes[pll(u,v)]=i+1;
	}
	return move(to);
}

bool dfs(ll v, ll p){
	each(u, to[v]){
		if (u==p)continue;

		if (seen[u]==0){
			seen[u]=1;
			bool isc=dfs(u, v);
			if (isc){
				cycle.push_back(v);
				return true;
			}
		}
		else{ //ぶつかった
			cycle.push_back(u);
			cycle.push_back(v);
			return true;
		}
	}
	return false;
}

void solve()
{
	ll n;  cin >> n;
	to = cinGraph(n,n,false);

	seen.resize(n);
	seen[0]=1;
	bool isc=dfs(0, -1);
	rep(i, 1, sz(cycle)-1){
		if (cycle[i]==cycle[0]){
			cycle.resize(i);
			break;
		}
	}
	vll ans;
	rep(i,0,sz(cycle)-1){
		ll v=cycle[i];
		ll u=cycle[(i+1)%sz(cycle)];
		ans.push_back(idxes[pll(v,u)]);
	}
	cout << sz(ans) << '\n';
	cout << ans << '\n';
}

int main(){
#if 1
	solve();
#else
	ll t;  cin >> t;
	rep(i, 0, t-1){
		solve();
	}
#endif
	return 0;
}
0