結果
問題 |
No.806 木を道に
|
ユーザー |
|
提出日時 | 2020-05-05 14:23:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 69 ms / 2,000 ms |
コード長 | 425 bytes |
コンパイル時間 | 2,711 ms |
コンパイル使用メモリ | 194,692 KB |
最終ジャッジ日時 | 2025-01-10 06:46:06 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:15:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | int n; scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:18:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 18 | int u,v; scanf("%d%d",&u,&v); u--; v--; | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using graph=vector<vector<int>>; void add_edge(graph& G,int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } int main(){ int n; scanf("%d",&n); graph T(n); rep(i,n-1){ int u,v; scanf("%d%d",&u,&v); u--; v--; add_edge(T,u,v); } int ans=0; rep(u,n) ans+=max(int(T[u].size())-2,0); printf("%d\n",ans); return 0; }