結果

問題 No.1103 Directed Length Sum
ユーザー umezoumezo
提出日時 2020-07-03 23:32:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 715 bytes
コンパイル時間 2,798 ms
コンパイル使用メモリ 236,684 KB
実行使用メモリ 307,976 KB
最終ジャッジ日時 2023-10-17 06:26:07
合計ジャッジ時間 15,122 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
73,568 KB
testcase_01 AC 44 ms
73,568 KB
testcase_02 WA -
testcase_03 AC 560 ms
83,160 KB
testcase_04 AC 702 ms
84,128 KB
testcase_05 AC 1,200 ms
91,784 KB
testcase_06 AC 462 ms
80,432 KB
testcase_07 AC 127 ms
75,416 KB
testcase_08 AC 182 ms
76,208 KB
testcase_09 AC 94 ms
74,624 KB
testcase_10 AC 242 ms
77,000 KB
testcase_11 AC 760 ms
85,184 KB
testcase_12 AC 464 ms
80,696 KB
testcase_13 AC 249 ms
77,264 KB
testcase_14 AC 81 ms
74,360 KB
testcase_15 AC 379 ms
79,112 KB
testcase_16 AC 849 ms
86,504 KB
testcase_17 AC 893 ms
87,032 KB
testcase_18 AC 242 ms
77,000 KB
testcase_19 AC 775 ms
85,448 KB
testcase_20 AC 109 ms
74,888 KB
testcase_21 AC 169 ms
75,944 KB
testcase_22 AC 634 ms
83,336 KB
testcase_23 AC 387 ms
79,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:42:6: warning: 'root' may be used uninitialized [-Wmaybe-uninitialized]
   42 |   rec(root,0);
      |   ~~~^~~~~~~~
main.cpp:34:6: note: 'root' was declared here
   34 |   ll root;
      |      ^~~~

ソースコード

diff #

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const int MOD=1e9+7;

vector<ll> D(1000010);  
vector<vector<ll>> C(1000010);

void rec(ll u, ll p){
  D[u]=p;
  if(!C[u].empty()){
    for(auto x:C[u]) rec(x,p+1);
  }
}

int main() {
  int n;
  cin>>n;
  
  vector<ll> P(1000010);
  
  int a,b;
  rep(i,n){
    cin>>a>>b;
    P[b]=a;
    C[a].push_back(b);
  }
  
  ll root;
  for(ll i=1;i<=n;i++){
    if(P[i]==0){
      root=i;
      break;
    }
  }
  
  rec(root,0);
    
  ll ans=0;
  for(ll i=1;i<=n;i++){
    ans+=(D[i]*(D[i]+1)/2)%MOD;
  }
  
  cout<<ans<<endl;

  return 0;
}
0