結果
問題 | No.1103 Directed Length Sum |
ユーザー |
|
提出日時 | 2020-07-04 20:16:06 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,278 bytes |
コンパイル時間 | 6,808 ms |
コンパイル使用メモリ | 135,872 KB |
最終ジャッジ日時 | 2025-01-11 15:45:11 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 21 TLE * 1 |
ソースコード
#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 += ((LLONG)pass * (LLONG)(pass + 1LL) / 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)); }