結果

問題 No.1103 Directed Length Sum
ユーザー uzzyuzzy
提出日時 2020-07-03 23:05:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 534 ms / 3,000 ms
コード長 1,015 bytes
コンパイル時間 2,504 ms
コンパイル使用メモリ 188,580 KB
実行使用メモリ 95,216 KB
最終ジャッジ日時 2023-10-17 06:06:24
合計ジャッジ時間 8,264 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
30,976 KB
testcase_01 AC 15 ms
30,976 KB
testcase_02 AC 296 ms
95,216 KB
testcase_03 AC 172 ms
35,492 KB
testcase_04 AC 293 ms
40,080 KB
testcase_05 AC 534 ms
46,752 KB
testcase_06 AC 171 ms
36,904 KB
testcase_07 AC 45 ms
32,404 KB
testcase_08 AC 60 ms
33,156 KB
testcase_09 AC 33 ms
31,880 KB
testcase_10 AC 84 ms
33,964 KB
testcase_11 AC 294 ms
40,916 KB
testcase_12 AC 158 ms
36,968 KB
testcase_13 AC 83 ms
34,048 KB
testcase_14 AC 26 ms
31,656 KB
testcase_15 AC 108 ms
35,648 KB
testcase_16 AC 338 ms
42,132 KB
testcase_17 AC 355 ms
42,628 KB
testcase_18 AC 83 ms
33,944 KB
testcase_19 AC 283 ms
41,160 KB
testcase_20 AC 34 ms
32,068 KB
testcase_21 AC 50 ms
32,952 KB
testcase_22 AC 237 ms
39,288 KB
testcase_23 AC 131 ms
35,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

ll kotae = 0;
const int mod = 1e9 + 7;

vector<int> E[1000001];
int dfs(int p, int d) {
	ll k = 1;
	for (int to : E[p]) {
		k += dfs(to, d + 1);
	}
	kotae += k * d % mod;
	return k;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	int atta[1000001] = {};
	rep(i, N - 1) {
		int a, b;
		cin >> a >> b;
		E[a].pb(b);
		atta[b] = 1;
	}
	int ne = 0;
	rep1(i, N) {
		if (atta[i] == 0) {
			ne = i;
			break;
		}
	}

	dfs(ne, 0);

	co(kotae% mod);



	Would you please return 0;
}
0