結果

問題 No.1582 Vertexes vs Edges
ユーザー 👑 NachiaNachia
提出日時 2021-07-02 21:33:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 951 bytes
コンパイル時間 825 ms
コンパイル使用メモリ 84,016 KB
実行使用メモリ 10,336 KB
最終ジャッジ日時 2023-09-11 21:23:08
合計ジャッジ時間 3,569 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,360 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 29 ms
9,604 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 16 ms
6,312 KB
testcase_09 AC 28 ms
9,204 KB
testcase_10 AC 19 ms
6,800 KB
testcase_11 AC 3 ms
4,384 KB
testcase_12 AC 13 ms
5,712 KB
testcase_13 AC 20 ms
7,292 KB
testcase_14 AC 22 ms
7,444 KB
testcase_15 AC 29 ms
8,680 KB
testcase_16 AC 15 ms
5,876 KB
testcase_17 AC 21 ms
7,088 KB
testcase_18 AC 35 ms
10,000 KB
testcase_19 AC 20 ms
7,400 KB
testcase_20 AC 19 ms
6,660 KB
testcase_21 AC 17 ms
6,556 KB
testcase_22 AC 30 ms
9,088 KB
testcase_23 AC 12 ms
5,364 KB
testcase_24 AC 6 ms
4,376 KB
testcase_25 AC 17 ms
6,328 KB
testcase_26 AC 14 ms
5,496 KB
testcase_27 AC 29 ms
8,552 KB
testcase_28 AC 10 ms
4,804 KB
testcase_29 AC 25 ms
7,788 KB
testcase_30 AC 16 ms
6,084 KB
testcase_31 AC 25 ms
7,760 KB
testcase_32 AC 11 ms
5,164 KB
testcase_33 AC 39 ms
10,284 KB
testcase_34 AC 40 ms
10,336 KB
testcase_35 AC 39 ms
10,240 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <atcoder/dsu>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int N;
vector<vector<int>> E;
vector<int> P;
vector<int> I;

vector<int> dp[2];

int main(){
  cin >> N;
  E.resize(N);
  rep(i,N-1){
    int u,v; cin >> u >> v; u--; v--;
    E[u].push_back(v);
    E[v].push_back(u);
  }
  P.assign(N,-1);
  I = {0};
  rep(i,I.size()){
    int p = I[i];
    for(int e : E[p]) if(P[p] != e){
      P[e] = p;
      I.push_back(e);
    }
  }

  rep(t,2) dp[t].assign(N,t);

  for(int i=N-1; i>=0; i--){
    int p = I[i];
    for(int e : E[p]) if(P[p] != e){
      dp[0][p] += dp[1][e];
      dp[1][p] += min(dp[1][e],dp[0][e]);
    }
  }

  int ans = min(dp[0][0],dp[1][0]);
  cout << ans << endl;
  return 0;
}

struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_inst;
0