結果

問題 No.1640 簡単な色塗り
ユーザー karinohitokarinohito
提出日時 2021-08-06 22:21:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,629 bytes
コンパイル時間 2,149 ms
コンパイル使用メモリ 192,812 KB
実行使用メモリ 96,164 KB
最終ジャッジ日時 2023-09-12 02:20:53
合計ジャッジ時間 21,357 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
7,852 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 348 ms
95,852 KB
testcase_05 AC 350 ms
96,164 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 334 ms
57,580 KB
testcase_11 AC 273 ms
47,944 KB
testcase_12 AC 231 ms
42,584 KB
testcase_13 AC 542 ms
86,344 KB
testcase_14 AC 541 ms
85,600 KB
testcase_15 AC 169 ms
31,820 KB
testcase_16 AC 211 ms
38,104 KB
testcase_17 AC 443 ms
71,980 KB
testcase_18 AC 29 ms
9,388 KB
testcase_19 AC 240 ms
42,332 KB
testcase_20 AC 325 ms
55,768 KB
testcase_21 AC 263 ms
46,068 KB
testcase_22 AC 21 ms
7,532 KB
testcase_23 AC 355 ms
59,964 KB
testcase_24 AC 84 ms
18,888 KB
testcase_25 AC 245 ms
42,916 KB
testcase_26 AC 403 ms
65,808 KB
testcase_27 AC 154 ms
30,544 KB
testcase_28 AC 507 ms
82,240 KB
testcase_29 AC 382 ms
65,040 KB
testcase_30 AC 41 ms
16,900 KB
testcase_31 AC 313 ms
93,640 KB
testcase_32 AC 268 ms
81,976 KB
testcase_33 AC 176 ms
56,784 KB
testcase_34 AC 234 ms
70,160 KB
testcase_35 AC 179 ms
56,892 KB
testcase_36 AC 44 ms
16,768 KB
testcase_37 AC 58 ms
22,320 KB
testcase_38 AC 293 ms
85,412 KB
testcase_39 AC 113 ms
38,576 KB
testcase_40 AC 116 ms
39,164 KB
testcase_41 AC 247 ms
71,904 KB
testcase_42 AC 138 ms
44,176 KB
testcase_43 AC 138 ms
45,756 KB
testcase_44 AC 137 ms
44,748 KB
testcase_45 AC 98 ms
34,780 KB
testcase_46 AC 43 ms
18,360 KB
testcase_47 AC 29 ms
12,804 KB
testcase_48 AC 292 ms
87,192 KB
testcase_49 AC 12 ms
7,456 KB
testcase_50 TLE -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
07_evil_01.txt -- -
07_evil_02.txt -- -
権限があれば一括ダウンロードができます

ソースコード

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() == 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