結果

問題 No.1103 Directed Length Sum
ユーザー KKT89KKT89
提出日時 2020-07-05 06:35:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 583 ms / 3,000 ms
コード長 938 bytes
コンパイル時間 1,758 ms
コンパイル使用メモリ 115,680 KB
実行使用メモリ 132,800 KB
最終ジャッジ日時 2023-10-21 19:53:00
合計ジャッジ時間 11,026 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
28,024 KB
testcase_01 AC 10 ms
27,208 KB
testcase_02 AC 349 ms
132,800 KB
testcase_03 AC 171 ms
42,548 KB
testcase_04 AC 315 ms
45,684 KB
testcase_05 AC 583 ms
54,820 KB
testcase_06 AC 185 ms
40,944 KB
testcase_07 AC 38 ms
32,196 KB
testcase_08 AC 58 ms
33,316 KB
testcase_09 AC 28 ms
31,412 KB
testcase_10 AC 83 ms
34,516 KB
testcase_11 AC 354 ms
46,920 KB
testcase_12 AC 201 ms
41,040 KB
testcase_13 AC 94 ms
34,640 KB
testcase_14 AC 25 ms
31,076 KB
testcase_15 AC 140 ms
39,072 KB
testcase_16 AC 417 ms
48,744 KB
testcase_17 AC 427 ms
49,476 KB
testcase_18 AC 85 ms
34,488 KB
testcase_19 AC 372 ms
47,292 KB
testcase_20 AC 33 ms
31,696 KB
testcase_21 AC 54 ms
33,012 KB
testcase_22 AC 281 ms
44,504 KB
testcase_23 AC 161 ms
39,544 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:49:8: warning: 's' may be used uninitialized [-Wmaybe-uninitialized]
   49 |     dfs(s);
      |     ~~~^~~
main.cpp:45:9: note: 's' was declared here
   45 |     int s;
      |         ^

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
using namespace std;
typedef long long int ll;
using ull = unsigned long long;

constexpr ll mod=1e9+7;
int n;
ll res=0;
vector<int> g[1001000];
int d[1001000];
ll dp[1001000];

void dfs(int s){
    d[s]=1;
    for(int t:g[s]){
        dfs(t);
        d[s]+=d[t];
        (dp[s]+=dp[t])%=mod;
    }
    dp[s]+=d[s]-1;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> n;
    vector<bool> v(n,true);
    for(int i=1;i<n;i++){
        int a,b; cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        v[b]=false;
    }
    int s;
    for(int i=0;i<n;i++){
        if(v[i])s=i;
    }
    dfs(s);
    for(int i=0;i<n;i++){
        (res+=dp[i])%=mod;
    }
    printf("%lld\n",res);
}
0