結果
| 問題 |
No.1103 Directed Length Sum
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2020-07-03 23:27:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 693 bytes |
| コンパイル時間 | 2,659 ms |
| コンパイル使用メモリ | 230,440 KB |
| 最終ジャッジ日時 | 2025-01-11 15:06:59 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 WA * 1 |
コンパイルメッセージ
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;
| ^~~~
ソースコード
#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<ll> D(1000010);
vector<vector<ll>> 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);
ll ans=0;
for(int i=1;i<=n;i++){
ans+=D[i]*(D[i]+1)/2;
}
cout<<ans<<endl;
return 0;
}
umezo