結果

問題 No.1103 Directed Length Sum
ユーザー takumattakumat
提出日時 2020-07-04 20:13:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,263 bytes
コンパイル時間 1,161 ms
コンパイル使用メモリ 111,580 KB
実行使用メモリ 151,804 KB
最終ジャッジ日時 2023-10-19 13:23:22
合計ジャッジ時間 23,385 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 947 ms
73,644 KB
testcase_04 AC 1,433 ms
43,144 KB
testcase_05 AC 2,698 ms
71,796 KB
testcase_06 AC 863 ms
29,288 KB
testcase_07 AC 147 ms
9,644 KB
testcase_08 AC 250 ms
12,812 KB
testcase_09 AC 82 ms
7,268 KB
testcase_10 AC 367 ms
16,176 KB
testcase_11 AC 1,568 ms
46,460 KB
testcase_12 AC 868 ms
29,240 KB
testcase_13 AC 401 ms
16,704 KB
testcase_14 AC 61 ms
6,212 KB
testcase_15 AC 670 ms
23,500 KB
testcase_16 AC 1,814 ms
51,936 KB
testcase_17 AC 1,942 ms
54,048 KB
testcase_18 AC 383 ms
16,176 KB
testcase_19 AC 1,634 ms
47,828 KB
testcase_20 AC 104 ms
8,060 KB
testcase_21 AC 219 ms
12,020 KB
testcase_22 AC 1,322 ms
39,712 KB
testcase_23 AC 721 ms
25,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;//998244353;

template<class _T> static void getval(_T& a) {
	std::cin >> a;
}
template<class _T> static void getval(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getval(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static LLONG dfs(std::vector<std::vector<int>>& graph, int here, int pass)
{
	LLONG ans = 0;
	for (auto it = graph[here].begin(); it != graph[here].end(); it++) {
		ans = (ans + dfs(graph, *it, pass + 1)) % MOD_NUM;
	}
	ans += (pass * (pass + 1) / 2LL) % MOD_NUM;
	ans %= MOD_NUM;

	return ans;
}

static void exec()
{
	int N;
	getval(N);

	std::set<int> vers;
	for (int i = 0; i < N; i++) {
		vers.insert(i);
	}
	std::vector<std::vector<int>> graph(N);
	for (int i = 1; i < N; i++) {
		int a, b;
		getval(a, b); a--; b--;
		graph[a].push_back(b);
		vers.erase(b);
	}

	printf("%lld\n", dfs(graph, *(vers.begin()), 0));
}

0