結果

問題 No.1103 Directed Length Sum
ユーザー leaf_1415leaf_1415
提出日時 2020-07-03 21:47:52
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 454 ms / 3,000 ms
コード長 1,150 bytes
コンパイル時間 2,019 ms
コンパイル使用メモリ 80,720 KB
実行使用メモリ 121,460 KB
最終ジャッジ日時 2024-09-17 00:04:01
合計ジャッジ時間 5,617 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:62:12: warning: ‘root’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |         dfs(root, 0);
      |         ~~~^~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007
using namespace std;
typedef pair<llint, llint> P;
llint n;
vector<llint> G[1000005];
bool used[1000005];
llint ans;
llint dfs(int v, llint d)
{
llint ret = 1;
for(int i = 0; i < G[v].size(); i++){
ret += dfs(G[v][i], d+1);
}
ans += ret * d % mod, ans %= mod;
return ret;
}
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
llint u, v;
for(int i = 1; i <= n-1; i++){
cin >> u >> v;
G[u].push_back(v);
used[v] = true;
}
llint root;
for(int i = 1; i <= n; i++){
if(!used[i]) root = i;
}
dfs(root, 0);
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0