結果

問題 No.1582 Vertexes vs Edges
ユーザー SSRSSSRS
提出日時 2021-07-02 21:58:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 804 bytes
コンパイル時間 1,616 ms
コンパイル使用メモリ 173,820 KB
実行使用メモリ 14,380 KB
最終ジャッジ日時 2023-09-11 21:50:47
合計ジャッジ時間 4,680 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 68 ms
13,256 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 11 ms
4,788 KB
testcase_08 AC 34 ms
8,012 KB
testcase_09 AC 63 ms
12,340 KB
testcase_10 AC 41 ms
8,860 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 28 ms
7,148 KB
testcase_13 AC 47 ms
9,480 KB
testcase_14 AC 47 ms
9,168 KB
testcase_15 AC 66 ms
11,520 KB
testcase_16 AC 32 ms
7,284 KB
testcase_17 AC 46 ms
8,932 KB
testcase_18 AC 78 ms
13,472 KB
testcase_19 AC 47 ms
9,788 KB
testcase_20 AC 44 ms
8,624 KB
testcase_21 AC 38 ms
8,236 KB
testcase_22 AC 70 ms
12,096 KB
testcase_23 AC 25 ms
6,440 KB
testcase_24 AC 13 ms
4,760 KB
testcase_25 AC 38 ms
7,812 KB
testcase_26 AC 28 ms
6,840 KB
testcase_27 AC 68 ms
11,248 KB
testcase_28 AC 20 ms
5,608 KB
testcase_29 AC 55 ms
10,148 KB
testcase_30 AC 35 ms
7,540 KB
testcase_31 AC 59 ms
10,144 KB
testcase_32 AC 25 ms
6,172 KB
testcase_33 AC 94 ms
14,380 KB
testcase_34 AC 93 ms
14,004 KB
testcase_35 AC 92 ms
14,072 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<vector<int>> E(N);
  for (int i = 0; i < N - 1; i++){
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    E[u].push_back(v);
    E[v].push_back(u);
  }
  vector<int> p(N, -1);
  vector<vector<int>> c(N);
  queue<int> Q;
  Q.push(0);
  vector<int> bfs;
  while (!Q.empty()){
    int v = Q.front();
    Q.pop();
    bfs.push_back(v);
    for (int w : E[v]){
      if (w != p[v]){
        p[w] = v;
        c[v].push_back(w);
        Q.push(w);
      }
    }
  }
  reverse(bfs.begin(), bfs.end());
  vector<int> dp1(N), dp2(N);
  for (int v : bfs){
    dp1[v] = 0;
    dp2[v] = 1;
    for (int w : c[v]){
      dp1[v] += dp2[w];
      dp2[v] += min(dp1[w], dp2[w]);
    }
  }
  cout << min(dp1[0], dp2[0]) << endl;
}
0