結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 356 ms
96,136 KB
testcase_05 AC 360 ms
96,048 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
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 39 ms
16,888 KB
testcase_31 AC 306 ms
93,660 KB
testcase_32 AC 257 ms
81,908 KB
testcase_33 AC 168 ms
56,952 KB
testcase_34 AC 213 ms
69,908 KB
testcase_35 AC 167 ms
57,132 KB
testcase_36 AC 38 ms
17,000 KB
testcase_37 AC 49 ms
22,280 KB
testcase_38 AC 272 ms
85,308 KB
testcase_39 AC 101 ms
38,372 KB
testcase_40 AC 105 ms
39,168 KB
testcase_41 AC 222 ms
72,012 KB
testcase_42 AC 125 ms
44,160 KB
testcase_43 AC 132 ms
45,688 KB
testcase_44 AC 126 ms
44,708 KB
testcase_45 AC 88 ms
34,724 KB
testcase_46 AC 39 ms
18,404 KB
testcase_47 AC 25 ms
12,768 KB
testcase_48 AC 279 ms
87,244 KB
testcase_49 AC 11 ms
7,692 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 1 ms
4,376 KB
testcase_52 AC 562 ms
96,032 KB
testcase_53 AC 581 ms
95,908 KB
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(k!=N&&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