結果

問題 No.1103 Directed Length Sum
ユーザー umezoumezo
提出日時 2020-07-03 23:23:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 696 bytes
コンパイル時間 2,771 ms
コンパイル使用メモリ 234,988 KB
実行使用メモリ 300,352 KB
最終ジャッジ日時 2023-10-17 06:21:49
合計ジャッジ時間 15,534 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
65,920 KB
testcase_01 AC 42 ms
65,920 KB
testcase_02 WA -
testcase_03 AC 557 ms
71,820 KB
testcase_04 AC 698 ms
74,896 KB
testcase_05 AC 1,209 ms
81,496 KB
testcase_06 AC 452 ms
71,728 KB
testcase_07 AC 128 ms
67,240 KB
testcase_08 AC 182 ms
68,032 KB
testcase_09 AC 94 ms
66,712 KB
testcase_10 AC 243 ms
68,824 KB
testcase_11 AC 755 ms
75,688 KB
testcase_12 AC 453 ms
71,728 KB
testcase_13 AC 247 ms
68,824 KB
testcase_14 AC 79 ms
66,448 KB
testcase_15 AC 362 ms
70,408 KB
testcase_16 AC 846 ms
77,008 KB
testcase_17 AC 880 ms
77,536 KB
testcase_18 AC 238 ms
68,824 KB
testcase_19 AC 774 ms
75,952 KB
testcase_20 AC 105 ms
66,976 KB
testcase_21 AC 166 ms
67,768 KB
testcase_22 AC 632 ms
74,104 KB
testcase_23 AC 386 ms
70,936 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:40:6: warning: 'root' may be used uninitialized [-Wmaybe-uninitialized]
   40 |   rec(root,0);
      |   ~~~^~~~~~~~
main.cpp:32:7: note: 'root' was declared here
   32 |   int 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;

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

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

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

  return 0;
}
0