結果
問題 | No.806 木を道に |
ユーザー |
|
提出日時 | 2019-08-06 00:23:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 918 bytes |
コンパイル時間 | 530 ms |
コンパイル使用メモリ | 71,808 KB |
実行使用メモリ | 9,216 KB |
最終ジャッジ日時 | 2024-07-18 13:50:44 |
合計ジャッジ時間 | 2,434 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
#include <iostream> #include <vector> #include <utility> using namespace std; using ll = long long int; #define PREPARED_ENVIRONMENT template <class T> std::ostream& operator<<(std::ostream& o, const std::vector<T>& v) { o << "{"; for (int i = 0; i < (int) v.size(); i++) o << (i > 0 ? ", " : "" ) << v[i]; o << "}"; return o; } template <class X, class Y> std::ostream& operator<<(std::ostream& o, const std::pair<X, Y>& p) { o << "(" << p.first << ", " << p.second << ")"; return o; } ll n; ll ans = 0; vector<vector<ll>> graph; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; graph = vector<vector<ll>>(n); for (int i = 0; i < (n - 1); i++) { int a, b; cin >> a >> b; a--; b--; graph[a].push_back(b); graph[b].push_back(a); } for (int i = 0; i < n; i++) { ans += max(0, (int) (graph[i].size())-2); } cout << ans << endl; return 0; }