結果

問題 No.1640 簡単な色塗り
ユーザー karinohitokarinohito
提出日時 2021-08-07 20:56:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,694 bytes
コンパイル時間 2,412 ms
コンパイル使用メモリ 193,708 KB
実行使用メモリ 96,336 KB
最終ジャッジ日時 2023-09-12 03:57:55
合計ジャッジ時間 19,531 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 361 ms
96,164 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 42 ms
16,768 KB
testcase_31 AC 309 ms
93,500 KB
testcase_32 AC 258 ms
81,924 KB
testcase_33 AC 165 ms
56,836 KB
testcase_34 AC 211 ms
70,040 KB
testcase_35 AC 163 ms
57,064 KB
testcase_36 AC 35 ms
17,040 KB
testcase_37 AC 47 ms
22,048 KB
testcase_38 AC 280 ms
85,340 KB
testcase_39 AC 109 ms
38,460 KB
testcase_40 AC 115 ms
39,224 KB
testcase_41 AC 234 ms
71,884 KB
testcase_42 AC 129 ms
44,612 KB
testcase_43 AC 136 ms
45,804 KB
testcase_44 AC 134 ms
44,708 KB
testcase_45 AC 95 ms
34,776 KB
testcase_46 AC 39 ms
18,388 KB
testcase_47 AC 25 ms
12,768 KB
testcase_48 AC 294 ms
87,136 KB
testcase_49 AC 11 ms
7,416 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
07_evil_01.txt WA -
07_evil_02.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <atcoder/all>
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
//using namespace atcoder;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using Graph = vector<vector<ll>>;
Graph G;
vll E;
vector<bool> seen;

int main() {

	ll N;
	cin >> N;
	Graph G(N);
	vector<tuple<ll, ll, ll>> edge(N);
	vll E(N, 0);
	vector<multiset<ll>> SE(N);
	map<pair<ll, ll>, queue<ll>> M;
	rep(i, N) {
		ll A, B;
		cin >> A >> B;
		A--; B--;
		edge[i] = make_tuple(A, B, -1);
		M[make_pair(min(A, B), max(A, B))].push(i);
		SE[A].insert(B);
		SE[B].insert(A);
	}
	queue<ll> Q;
	rep(i, N) {
		if (SE[i].size() == 1) {
			Q.push(i);
		}
		else if (SE[i].size() == 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	ll k = 0;
	ll j = 0;
	while (1) {
		while (!Q.empty()) {
			auto p = Q.front();
			Q.pop();
			ll n = *SE[p].begin();
			ll m = M[make_pair(min(p, n), max(p, n))].front();
			M[make_pair(min(p, n), max(p, n))].pop();
			edge[m] = make_tuple(p, n, p);
			k++;
			SE[p].erase(SE[p].find(n));
			SE[n].erase(SE[n].find(p));
			if(SE[n].size()==0){
				cout<<"No"<<endl;
				return 0;
			}
			if (SE[n].size() == 1) {
				Q.push(n);
			}

		}
		if (k == N) {
			cout << "Yes" << endl;
			rep(i, N) {
				cout << 1+get<2>(edge[i]) << endl;
			}
			return 0;
		}
		while (SE[j].size() == 0) {
			j++;
		}
		ll p = j;
		ll n = *SE[p].begin();
		ll m = M[make_pair(min(p, n), max(p, n))].front();
		M[make_pair(min(p, n), max(p, n))].pop();
		edge[m] = make_tuple(p, n, p);
		k++;
		SE[p].erase(SE[p].find(n));
		SE[n].erase(SE[n].find(p));
		if (SE[n].size() == 1) {
			Q.push(n);
		}

	}
}
0