結果
問題 | No.806 木を道に |
ユーザー |
![]() |
提出日時 | 2019-03-22 21:42:37 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 61 ms / 2,000 ms |
コード長 | 390 bytes |
コンパイル時間 | 694 ms |
コンパイル使用メモリ | 74,580 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-19 03:12:24 |
合計ジャッジ時間 | 2,406 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
#include <vector>#include <iostream>#include <algorithm>using namespace std;int main() {int N;cin >> N;vector<int> deg(N);for (int i = 0; i < N - 1; ++i) {int a, b;cin >> a >> b; --a, --b;++deg[a], ++deg[b];}sort(deg.begin(), deg.end());int ans = 0;for (int i = 0; i < N; ++i) {ans += abs(deg[i] - (i <= 1 ? 1 : 2));}cout << ans / 2 << endl;return 0;}