結果

問題 No.1103 Directed Length Sum
ユーザー QCFiumQCFium
提出日時 2020-07-14 18:30:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,502 bytes
コンパイル時間 2,350 ms
コンパイル使用メモリ 174,980 KB
実行使用メモリ 18,920 KB
最終ジャッジ日時 2023-08-11 08:21:09
合計ジャッジ時間 10,338 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 15 ms
9,236 KB
testcase_08 AC 22 ms
12,160 KB
testcase_09 AC 10 ms
6,676 KB
testcase_10 AC 39 ms
15,600 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 43 ms
15,976 KB
testcase_14 AC 8 ms
5,752 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 41 ms
15,596 KB
testcase_19 RE -
testcase_20 AC 11 ms
7,536 KB
testcase_21 AC 20 ms
11,452 KB
testcase_22 RE -
testcase_23 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:39:15: 警告: ‘void* memset(void*, int, size_t)’ specified size between 18446744071562068017 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
   39 |         memset(used, 0, sizeof(used));
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

struct FastIO {
	char buf[3000000];
	char *ptr = buf;
	void read() {
		int size;
		size = fread(buf, 1, sizeof(buf) - 1, stdin);
		buf[size] = '\0';
		ptr = buf;
	}
	FastIO () {
		read();
	}
	void inc() {
		ptr++;
		// if (++ptr == buf + sizeof(buf) || !*ptr) read();
	}
	template<typename Integer> Integer read() {
		bool neg = false;
		Integer res = 0;
		while ((*ptr < '0' || *ptr > '9') && *ptr != '-') inc();
		if (*ptr == '-') neg = true, inc();
		while (*ptr >= '0' && *ptr <= '9') res = res * 10 + *ptr - '0', inc();
		return neg ? -res : res;
	}
} fastio;
#define ri fastio.read<int>
#define rs64 fastio.read<int64_t>


std::vector<std::vector<int> > hen;

int main() {
	int n = ri();
	int degree[n];
	memset(degree, 0, sizeof(degree));
	bool used[n];
	memset(used, 0, sizeof(used));
	std::pair<int, int> hens[n - 1];
	for (int i = 0; i + 1 < n; i++) {
		hens[i].first = ri() - 1;
		hens[i].second = ri() - 1;
		degree[hens[i].first]++;
		used[hens[i].second] = true;
	}
	
	int root = std::find(used, used + n, 0) - used;
	hen.resize(n);
	for (int i = 0; i < n; i++) hen[i].resize(degree[i]);
	for (auto i : hens) hen[i.first][--degree[i.first]] = i.second;
	
	int depth[n];
	depth[root] = 0;
	std::queue<int> que;
	que.push(root);
	int64_t res = 0;
	while (que.size()) {
		int i = que.front();
		que.pop();
		res += (int64_t) depth[i] * (depth[i] + 1) / 2;
		for (auto j : hen[i]) depth[j] = depth[i] + 1, que.push(j);
	}
	printf("%" PRId64 "\n", res);
	return 0;
}
0