結果
問題 | No.1582 Vertexes vs Edges |
ユーザー | kwm_t |
提出日時 | 2021-07-03 16:10:46 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 38 ms / 2,000 ms |
コード長 | 1,364 bytes |
コンパイル時間 | 3,163 ms |
コンパイル使用メモリ | 166,564 KB |
実行使用メモリ | 11,304 KB |
最終ジャッジ日時 | 2023-09-12 20:45:31 |
合計ジャッジ時間 | 4,199 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
8,172 KB |
testcase_01 | AC | 4 ms
8,076 KB |
testcase_02 | AC | 4 ms
8,112 KB |
testcase_03 | AC | 4 ms
8,124 KB |
testcase_04 | AC | 5 ms
8,160 KB |
testcase_05 | AC | 28 ms
10,864 KB |
testcase_06 | AC | 5 ms
8,472 KB |
testcase_07 | AC | 7 ms
8,596 KB |
testcase_08 | AC | 16 ms
9,692 KB |
testcase_09 | AC | 28 ms
10,756 KB |
testcase_10 | AC | 19 ms
9,708 KB |
testcase_11 | AC | 6 ms
8,360 KB |
testcase_12 | AC | 13 ms
9,184 KB |
testcase_13 | AC | 22 ms
9,912 KB |
testcase_14 | AC | 21 ms
9,888 KB |
testcase_15 | AC | 28 ms
10,624 KB |
testcase_16 | AC | 15 ms
9,352 KB |
testcase_17 | AC | 20 ms
9,988 KB |
testcase_18 | AC | 32 ms
11,100 KB |
testcase_19 | AC | 22 ms
9,924 KB |
testcase_20 | AC | 19 ms
9,716 KB |
testcase_21 | AC | 17 ms
9,568 KB |
testcase_22 | AC | 28 ms
10,792 KB |
testcase_23 | AC | 13 ms
9,068 KB |
testcase_24 | AC | 8 ms
8,588 KB |
testcase_25 | AC | 17 ms
9,496 KB |
testcase_26 | AC | 13 ms
9,200 KB |
testcase_27 | AC | 29 ms
10,564 KB |
testcase_28 | AC | 11 ms
8,880 KB |
testcase_29 | AC | 23 ms
10,188 KB |
testcase_30 | AC | 16 ms
9,380 KB |
testcase_31 | AC | 25 ms
10,184 KB |
testcase_32 | AC | 12 ms
8,976 KB |
testcase_33 | AC | 37 ms
11,304 KB |
testcase_34 | AC | 38 ms
11,296 KB |
testcase_35 | AC | 37 ms
11,304 KB |
testcase_36 | AC | 4 ms
8,112 KB |
testcase_37 | AC | 4 ms
8,036 KB |
testcase_38 | AC | 4 ms
8,172 KB |
ソースコード
#include "bits/stdc++.h" //#include "atcoder/all" using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; //const bool debug = false; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" #define P pair<int,int> template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } vector<int>to[200005]; P dfs(int v, int d = 0, int p = -1) { P ret = { 1,0 }; for (int e : to[v]) { if (p == e) continue; P get = dfs(e, d + 1, v); ret.first += get.second; ret.second += max(get.first, get.second); } return ret; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; rep(i, n - 1) { int a, b; cin >> a >> b; a--; b--; to[a].push_back(b); to[b].push_back(a); } auto p = dfs(0); cout << n - max(p.first, p.second) << endl; return 0; }