提出 #11177694


ソースコード 拡げる

/**
 * Contest : Social Infrastructure Information System Division, Hitachi Programming Contest 2020
 * Contest URL : https://atcoder.jp/contests/hitachi2020/
 * Problem : C - ThREE
 * Problem URL : https://atcoder.jp/contests/hitachi2020/tasks/hitachi2020_c
 */

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair < int, int >;

// This section is for Policy Based Data Structure, more precisely Ordered Set.
// All Functions of set works here, in addition we have order_of_key() and find_by_order() function. find_by_order() returns iterator
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<functional>
using namespace __gnu_pbds;
// All unique value
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set1;
// For storing multiple occurance of same value we need to use pair. In pair first value is our key and second is useless count variable.
// order_of_key(make_pair(key, 0)) returns first occurance of a value, order_of_key(make_pair(key, INT_MAX)) returns last occurance.
typedef tree<pair<int, int>, null_type, less<pair<int,int> >,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// Policy End


int main() {
	cin.tie (0);
	ios::sync_with_stdio (false);
	int n, a, b;
	cin >> n;
	vector < vector < int > > g (n);
	for (int i = 1; i < n; i++) {
		cin >> a >> b;
		a--, b--;
		g[a].push_back (b);
		g[b].push_back (a);
	}
	vector < int > nodes[2];
	std::function<void(int,int,int)> dfs = [&] (int u, int p, int index) {
		nodes[index].push_back (u);
		for (int v : g[u]) {
			if (v != p) {
				dfs (v, u, 1 - index);
			}
		}
	};
	dfs (0, -1, 0);
	int red = 0, blue = 1;
	if (nodes[red].size() > nodes[blue].size()) {
		red = 1, blue = 0;
	}
	int x = n / 3;
	vector < int > p (n);
	vector < int > visited (n + 1);
	if (nodes[red].size() <= x) {
		int current = 3;
		for (int u : nodes[red]) {
			p[u] = current;
			visited[current] = true;
			current += 3;
		}
		current = 1;
		for (int u : nodes[blue]) {
			while (visited[current]) {
				current++;
			}
			p[u] = current;
			visited[current] = true;
			current++;
		}
	} else {
		int one = 1, two = 2, three = 3;
		for (int u : nodes[red]) {
			if (one <= n){
				p[u] = one;
				one += 3;
			} else {
				p[u] = three;
				three += 3;
			}
		}
		for (int v : nodes[blue]) {
			if (two <= n) {
				p[v] = two;
				two += 3;
			} else {
				p[v] = three;
				three += 3;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << p[i] << " ";
	}
	cout << "\n";
	
	return 0;
}

提出情報

提出日時
問題 C - ThREE
ユーザ himanshup
言語 C++14 (GCC 5.4.1)
得点 600
コード長 2659 Byte
結果 AC
実行時間 98 ms
メモリ 23540 KiB

ジャッジ結果

セット名 All sample
得点 / 配点 600 / 600 0 / 0
結果
AC × 57
AC × 1
セット名 テストケース
All 00_sample_01, 20_small_01, 20_small_02, 20_small_03, 20_small_04, 20_small_05, 30_large_01, 30_large_02, 30_large_03, 40_line_01, 40_line_02, 40_line_03, 50_star_01, 50_star_02, 50_star_03, 60_hand_01, 60_hand_02, 60_hand_03, 60_hand_04, 60_hand_05, 60_hand_06, 60_hand_07, 60_hand_08, 60_hand_09, 60_hand_10, 60_hand_11, 60_hand_12, 60_hand_13, 60_hand_14, 60_hand_15, 60_hand_16, 60_hand_17, 60_hand_18, 60_hand_19, 60_hand_20, 60_hand_21, 60_hand_22, 60_hand_23, 60_hand_24, 60_hand_25, 60_hand_26, 60_hand_27, 60_hand_28, 60_hand_29, 60_hand_30, 70_dense_01, 70_dense_02, 70_dense_03, 70_dense_04, 70_dense_05, 70_dense_06, 70_dense_07, 70_dense_08, 70_dense_09, 70_dense_10, 90_hand_01, 90_hand_02
sample 00_sample_01
ケース名 結果 実行時間 メモリ
00_sample_01 AC 1 ms 256 KiB
20_small_01 AC 1 ms 256 KiB
20_small_02 AC 1 ms 256 KiB
20_small_03 AC 1 ms 256 KiB
20_small_04 AC 1 ms 256 KiB
20_small_05 AC 1 ms 256 KiB
30_large_01 AC 98 ms 15092 KiB
30_large_02 AC 97 ms 15092 KiB
30_large_03 AC 97 ms 15008 KiB
40_line_01 AC 63 ms 23540 KiB
40_line_02 AC 49 ms 14376 KiB
40_line_03 AC 37 ms 11644 KiB
50_star_01 AC 41 ms 9208 KiB
50_star_02 AC 41 ms 8824 KiB
50_star_03 AC 5 ms 1152 KiB
60_hand_01 AC 21 ms 4732 KiB
60_hand_02 AC 21 ms 4796 KiB
60_hand_03 AC 4 ms 1024 KiB
60_hand_04 AC 5 ms 1152 KiB
60_hand_05 AC 30 ms 6712 KiB
60_hand_06 AC 40 ms 7928 KiB
60_hand_07 AC 30 ms 6524 KiB
60_hand_08 AC 26 ms 6012 KiB
60_hand_09 AC 10 ms 2432 KiB
60_hand_10 AC 21 ms 4732 KiB
60_hand_11 AC 40 ms 8964 KiB
60_hand_12 AC 53 ms 11252 KiB
60_hand_13 AC 29 ms 6652 KiB
60_hand_14 AC 10 ms 2304 KiB
60_hand_15 AC 23 ms 4988 KiB
60_hand_16 AC 6 ms 1536 KiB
60_hand_17 AC 16 ms 3456 KiB
60_hand_18 AC 58 ms 12404 KiB
60_hand_19 AC 6 ms 1408 KiB
60_hand_20 AC 58 ms 13176 KiB
60_hand_21 AC 21 ms 4732 KiB
60_hand_22 AC 60 ms 12408 KiB
60_hand_23 AC 61 ms 12664 KiB
60_hand_24 AC 76 ms 16752 KiB
60_hand_25 AC 44 ms 10232 KiB
60_hand_26 AC 8 ms 1664 KiB
60_hand_27 AC 38 ms 8696 KiB
60_hand_28 AC 43 ms 9720 KiB
60_hand_29 AC 4 ms 1024 KiB
60_hand_30 AC 4 ms 896 KiB
70_dense_01 AC 24 ms 5372 KiB
70_dense_02 AC 33 ms 6776 KiB
70_dense_03 AC 27 ms 5752 KiB
70_dense_04 AC 34 ms 6776 KiB
70_dense_05 AC 31 ms 6404 KiB
70_dense_06 AC 25 ms 5496 KiB
70_dense_07 AC 29 ms 6392 KiB
70_dense_08 AC 24 ms 5372 KiB
70_dense_09 AC 9 ms 1920 KiB
70_dense_10 AC 19 ms 4220 KiB
90_hand_01 AC 1 ms 256 KiB
90_hand_02 AC 1 ms 256 KiB