結果

問題 No.1582 Vertexes vs Edges
ユーザー butsurizukibutsurizuki
提出日時 2021-06-18 23:04:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 817 bytes
コンパイル時間 6,755 ms
コンパイル使用メモリ 305,168 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-09-11 14:27:37
合計ジャッジ時間 9,556 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 34 ms
8,180 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 18 ms
5,536 KB
testcase_09 AC 32 ms
7,592 KB
testcase_10 AC 20 ms
6,044 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 14 ms
5,300 KB
testcase_13 AC 24 ms
6,312 KB
testcase_14 AC 25 ms
6,296 KB
testcase_15 AC 36 ms
7,368 KB
testcase_16 AC 17 ms
5,228 KB
testcase_17 AC 24 ms
6,048 KB
testcase_18 AC 42 ms
8,624 KB
testcase_19 AC 24 ms
6,328 KB
testcase_20 AC 23 ms
6,044 KB
testcase_21 AC 20 ms
5,856 KB
testcase_22 AC 37 ms
8,088 KB
testcase_23 AC 14 ms
4,728 KB
testcase_24 AC 7 ms
4,380 KB
testcase_25 AC 19 ms
5,520 KB
testcase_26 AC 15 ms
5,180 KB
testcase_27 AC 36 ms
7,360 KB
testcase_28 AC 11 ms
4,516 KB
testcase_29 AC 29 ms
6,800 KB
testcase_30 AC 18 ms
5,492 KB
testcase_31 AC 31 ms
6,812 KB
testcase_32 AC 13 ms
4,792 KB
testcase_33 AC 47 ms
8,656 KB
testcase_34 AC 52 ms
8,756 KB
testcase_35 AC 51 ms
8,752 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "testlib.h"
#include<bits/stdc++.h>

using namespace std;
using Graph=vector<vector<int>>;
using pi=pair<int,int>;

int cnt=0;
pi rep(int v,int pv,Graph &g){
  cnt++;
  pi res={0,0};
  for(auto &nx : g[v]){
    if(nx==pv){continue;}
    pi ch=rep(nx,v,g);
    res.first+=max(ch.first,ch.second);
    res.second+=ch.first;
  }
  res.second++;
  return res;
}

int main(int argc, char* argv[]){
  registerValidation(argc, argv);
  int n=inf.readInt(2,100000);inf.readEoln();
  Graph g(n);
  for(int i=1;i<n;i++){
    int u=inf.readInt(1,n);inf.readSpace();
    int v=inf.readInt(1,n);inf.readEoln();
    u--;v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  pi res=rep(0,-1,g);
  ensuref(cnt==n,"The graph isn't connected");
  inf.readEof();
  cout << n-max(res.first,res.second) << '\n';
  return 0;
}
0