結果
問題 |
No.1103 Directed Length Sum
|
ユーザー |
![]() |
提出日時 | 2020-07-03 23:35:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 724 bytes |
コンパイル時間 | 5,267 ms |
コンパイル使用メモリ | 226,608 KB |
最終ジャッジ日時 | 2025-01-11 15:09:45 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 21 WA * 1 |
コンパイルメッセージ
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; | ^~~~
ソースコード
#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=(ans+(D[i]*(D[i]+1))%MOD/2)%MOD; } cout<<ans<<endl; return 0; }