結果

問題 No.1640 簡単な色塗り
ユーザー 👑 kmjpkmjp
提出日時 2021-08-07 00:03:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,328 bytes
コンパイル時間 2,303 ms
コンパイル使用メモリ 210,568 KB
実行使用メモリ 31,668 KB
最終ジャッジ日時 2023-09-12 03:28:51
合計ジャッジ時間 29,973 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,756 KB
testcase_01 AC 5 ms
9,708 KB
testcase_02 AC 5 ms
9,708 KB
testcase_03 AC 5 ms
9,752 KB
testcase_04 AC 198 ms
25,392 KB
testcase_05 AC 197 ms
25,464 KB
testcase_06 AC 5 ms
9,704 KB
testcase_07 AC 5 ms
9,716 KB
testcase_08 AC 4 ms
9,756 KB
testcase_09 AC 4 ms
9,764 KB
testcase_10 AC 635 ms
18,844 KB
testcase_11 AC 490 ms
17,096 KB
testcase_12 AC 369 ms
16,192 KB
testcase_13 AC 1,603 ms
23,692 KB
testcase_14 AC 1,695 ms
23,668 KB
testcase_15 AC 243 ms
14,200 KB
testcase_16 AC 333 ms
15,400 KB
testcase_17 AC 1,194 ms
21,396 KB
testcase_18 AC 39 ms
10,880 KB
testcase_19 AC 383 ms
16,320 KB
testcase_20 AC 677 ms
18,300 KB
testcase_21 AC 424 ms
16,836 KB
testcase_22 AC 26 ms
10,544 KB
testcase_23 AC 770 ms
19,256 KB
testcase_24 AC 114 ms
12,136 KB
testcase_25 AC 415 ms
16,332 KB
testcase_26 AC 992 ms
20,212 KB
testcase_27 AC 215 ms
14,072 KB
testcase_28 AC 1,319 ms
22,972 KB
testcase_29 AC 890 ms
19,984 KB
testcase_30 AC 18 ms
12,400 KB
testcase_31 AC 200 ms
31,668 KB
testcase_32 AC 145 ms
25,508 KB
testcase_33 AC 91 ms
19,644 KB
testcase_34 AC 136 ms
25,248 KB
testcase_35 AC 69 ms
20,044 KB
testcase_36 AC 19 ms
12,268 KB
testcase_37 AC 24 ms
13,016 KB
testcase_38 AC 147 ms
27,088 KB
testcase_39 AC 46 ms
17,736 KB
testcase_40 AC 45 ms
16,404 KB
testcase_41 AC 90 ms
22,072 KB
testcase_42 AC 51 ms
17,904 KB
testcase_43 AC 69 ms
19,784 KB
testcase_44 AC 54 ms
17,356 KB
testcase_45 AC 40 ms
15,760 KB
testcase_46 AC 18 ms
12,260 KB
testcase_47 AC 14 ms
11,436 KB
testcase_48 AC 173 ms
26,548 KB
testcase_49 AC 8 ms
10,620 KB
testcase_50 AC 4 ms
9,716 KB
testcase_51 AC 4 ms
9,704 KB
testcase_52 AC 394 ms
30,588 KB
testcase_53 TLE -
07_evil_01.txt -- -
07_evil_02.txt -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#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 ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

template<class V> class MaxFlow_dinic {
public:
	struct edge { int to,reve;V cap;};
	static const int MV = 202020;
	vector<edge> E[MV];
	int itr[MV],lev[MV];
	void add_edge(int x,int y,V cap,bool undir=false) {
		E[x].push_back((edge){y,(int)E[y].size(),cap});
		E[y].push_back((edge){x,(int)E[x].size()-1,undir?cap:0});
	}
	void bfs(int cur) {
		MINUS(lev);
		queue<int> q;
		lev[cur]=0;
		q.push(cur);
		while(q.size()) {
			int v=q.front(); q.pop();
			FORR(e,E[v]) if(e.cap>0 && lev[e.to]<0) lev[e.to]=lev[v]+1, q.push(e.to);
		}
	}
	V dfs(int from,int to,V cf) {
		if(from==to) return cf;
		for(;itr[from]<E[from].size();itr[from]++) {
			edge* e=&E[from][itr[from]];
			if(e->cap>0 && lev[from]<lev[e->to]) {
				V f=dfs(e->to,to,min(cf,e->cap));
				if(f>0) {
					e->cap-=f;
					E[e->to][e->reve].cap += f;
					return f;
				}
			}
		}
		return 0;
	}
	V maxflow(int from, int to) {
		V fl=0,tf;
		while(1) {
			bfs(from);
			if(lev[to]<0) return fl;
			ZERO(itr);
			while((tf=dfs(from,to,numeric_limits<V>::max()))>0) fl+=tf;
		}
	}
};

MaxFlow_dinic<int> mf;
int N;
int A[101010],B[101010];


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		mf.add_edge(200000,i,1);
		mf.add_edge(100000+i,200001,1);
		cin>>A[i]>>B[i];
		A[i]--;
		B[i]--;
		mf.add_edge(i,100000+A[i],1);
		mf.add_edge(i,100000+B[i],1);
	}
	if(mf.maxflow(200000,200001)!=N) {
		cout<<"No"<<endl;
	}
	else {
		cout<<"Yes"<<endl;
		FOR(i,N) {
			FORR(e,mf.E[i]) if(e.to>=100000&&e.cap==0) cout<<(e.to-100000+1)<<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