結果

問題 No.1254 補強への架け橋
ユーザー 👑 kmjpkmjp
提出日時 2020-10-09 23:24:59
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,241 bytes
コンパイル時間 2,288 ms
コンパイル使用メモリ 212,112 KB
実行使用メモリ 27,100 KB
最終ジャッジ日時 2023-09-27 19:48:33
合計ジャッジ時間 12,971 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
17,636 KB
testcase_01 AC 7 ms
17,768 KB
testcase_02 AC 6 ms
17,556 KB
testcase_03 AC 7 ms
17,700 KB
testcase_04 AC 7 ms
17,676 KB
testcase_05 AC 7 ms
17,564 KB
testcase_06 AC 7 ms
17,524 KB
testcase_07 AC 7 ms
17,552 KB
testcase_08 AC 7 ms
17,572 KB
testcase_09 AC 7 ms
17,672 KB
testcase_10 AC 6 ms
17,784 KB
testcase_11 AC 7 ms
17,572 KB
testcase_12 AC 7 ms
17,768 KB
testcase_13 AC 7 ms
17,576 KB
testcase_14 AC 7 ms
17,560 KB
testcase_15 AC 6 ms
17,512 KB
testcase_16 AC 7 ms
17,560 KB
testcase_17 AC 7 ms
17,632 KB
testcase_18 AC 7 ms
17,516 KB
testcase_19 AC 7 ms
17,636 KB
testcase_20 AC 7 ms
17,536 KB
testcase_21 AC 7 ms
17,700 KB
testcase_22 AC 7 ms
17,516 KB
testcase_23 AC 7 ms
17,684 KB
testcase_24 AC 7 ms
17,616 KB
testcase_25 AC 7 ms
17,528 KB
testcase_26 AC 6 ms
17,584 KB
testcase_27 AC 7 ms
17,624 KB
testcase_28 AC 7 ms
17,716 KB
testcase_29 AC 6 ms
17,636 KB
testcase_30 AC 7 ms
17,612 KB
testcase_31 AC 7 ms
17,576 KB
testcase_32 AC 7 ms
17,632 KB
testcase_33 AC 8 ms
17,584 KB
testcase_34 AC 7 ms
17,524 KB
testcase_35 AC 7 ms
17,580 KB
testcase_36 AC 7 ms
17,576 KB
testcase_37 AC 7 ms
17,576 KB
testcase_38 AC 7 ms
17,572 KB
testcase_39 AC 7 ms
17,564 KB
testcase_40 AC 7 ms
17,576 KB
testcase_41 AC 7 ms
17,668 KB
testcase_42 AC 7 ms
17,568 KB
testcase_43 AC 8 ms
17,728 KB
testcase_44 AC 7 ms
17,656 KB
testcase_45 AC 7 ms
17,664 KB
testcase_46 AC 7 ms
17,644 KB
testcase_47 AC 6 ms
17,604 KB
testcase_48 AC 7 ms
17,628 KB
testcase_49 AC 7 ms
17,592 KB
testcase_50 AC 7 ms
17,728 KB
testcase_51 AC 7 ms
17,764 KB
testcase_52 AC 7 ms
17,856 KB
testcase_53 AC 7 ms
17,640 KB
testcase_54 AC 7 ms
17,856 KB
testcase_55 AC 7 ms
17,652 KB
testcase_56 AC 7 ms
17,788 KB
testcase_57 AC 7 ms
17,628 KB
testcase_58 AC 7 ms
17,628 KB
testcase_59 AC 6 ms
17,576 KB
testcase_60 AC 7 ms
17,544 KB
testcase_61 AC 7 ms
17,756 KB
testcase_62 AC 6 ms
17,720 KB
testcase_63 AC 12 ms
18,544 KB
testcase_64 AC 8 ms
17,832 KB
testcase_65 AC 10 ms
18,204 KB
testcase_66 AC 9 ms
18,128 KB
testcase_67 AC 8 ms
17,804 KB
testcase_68 AC 10 ms
18,068 KB
testcase_69 AC 11 ms
18,288 KB
testcase_70 AC 8 ms
17,880 KB
testcase_71 AC 8 ms
17,748 KB
testcase_72 AC 10 ms
18,300 KB
testcase_73 AC 8 ms
17,836 KB
testcase_74 AC 11 ms
18,220 KB
testcase_75 AC 9 ms
18,080 KB
testcase_76 AC 7 ms
17,728 KB
testcase_77 AC 9 ms
18,012 KB
testcase_78 AC 11 ms
18,428 KB
testcase_79 AC 12 ms
18,484 KB
testcase_80 AC 11 ms
18,424 KB
testcase_81 AC 11 ms
18,540 KB
testcase_82 AC 11 ms
18,456 KB
testcase_83 AC 79 ms
27,056 KB
testcase_84 AC 76 ms
26,780 KB
testcase_85 AC 52 ms
23,340 KB
testcase_86 AC 67 ms
25,456 KB
testcase_87 AC 71 ms
26,188 KB
testcase_88 AC 14 ms
18,988 KB
testcase_89 AC 95 ms
26,984 KB
testcase_90 AC 49 ms
23,588 KB
testcase_91 AC 38 ms
22,284 KB
testcase_92 AC 21 ms
20,060 KB
testcase_93 AC 65 ms
25,044 KB
testcase_94 AC 58 ms
24,348 KB
testcase_95 AC 56 ms
24,324 KB
testcase_96 AC 78 ms
26,432 KB
testcase_97 AC 33 ms
21,596 KB
testcase_98 AC 87 ms
26,532 KB
testcase_99 AC 46 ms
22,996 KB
testcase_100 AC 86 ms
27,100 KB
testcase_101 AC 20 ms
19,852 KB
testcase_102 AC 13 ms
18,824 KB
testcase_103 AC 23 ms
20,032 KB
testcase_104 AC 29 ms
21,020 KB
testcase_105 AC 71 ms
25,320 KB
testcase_106 AC 38 ms
21,960 KB
testcase_107 AC 91 ms
26,852 KB
testcase_108 AC 85 ms
26,860 KB
testcase_109 AC 61 ms
24,964 KB
testcase_110 AC 54 ms
24,204 KB
testcase_111 AC 57 ms
24,836 KB
testcase_112 AC 28 ms
20,776 KB
testcase_113 AC 53 ms
24,140 KB
testcase_114 AC 36 ms
21,884 KB
testcase_115 AC 16 ms
19,176 KB
testcase_116 AC 42 ms
22,584 KB
testcase_117 AC 28 ms
20,788 KB
testcase_118 AC 76 ms
26,380 KB
testcase_119 AC 44 ms
22,928 KB
testcase_120 AC 81 ms
26,092 KB
testcase_121 AC 27 ms
20,436 KB
testcase_122 AC 39 ms
22,448 KB
testcase_123 AC 7 ms
17,516 KB
testcase_124 AC 72 ms
27,084 KB
testcase_125 AC 75 ms
26,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
set<pair<int,int>> E[303030];
int need[303030];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>x>>y;
		E[x-1].insert({y-1,i});
		E[y-1].insert({x-1,i});
	}
	queue<int> Q;
	FOR(i,N) if(E[i].size()==1) Q.push(i);
	while(Q.size()) {
		x=Q.front();
		Q.pop();
		y=E[x].begin()->first;
		i=E[x].begin()->second;
		need[i]=1;
		E[x].clear();
		E[y].erase({x,i});
		if(E[y].size()==1) Q.push(y);
	}
	
	cout<<count(need,need+N,0)<<endl;
	FOR(i,N) if(need[i]==0) cout<<(i+1)<<" ";
	cout<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0