結果

問題 No.2677 Minmax Independent Set
ユーザー 👑 kmjpkmjp
提出日時 2024-03-18 22:49:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 1,429 bytes
コンパイル時間 2,125 ms
コンパイル使用メモリ 205,104 KB
実行使用メモリ 28,608 KB
最終ジャッジ日時 2024-03-18 22:49:55
合計ジャッジ時間 9,086 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,152 KB
testcase_01 AC 4 ms
9,152 KB
testcase_02 AC 4 ms
9,152 KB
testcase_03 AC 4 ms
9,152 KB
testcase_04 AC 3 ms
9,152 KB
testcase_05 AC 86 ms
17,344 KB
testcase_06 AC 86 ms
17,472 KB
testcase_07 AC 101 ms
17,600 KB
testcase_08 AC 85 ms
17,856 KB
testcase_09 AC 93 ms
18,368 KB
testcase_10 AC 97 ms
16,560 KB
testcase_11 AC 66 ms
16,436 KB
testcase_12 AC 104 ms
28,608 KB
testcase_13 AC 95 ms
20,400 KB
testcase_14 AC 87 ms
20,496 KB
testcase_15 AC 100 ms
22,980 KB
testcase_16 AC 94 ms
16,320 KB
testcase_17 AC 94 ms
16,320 KB
testcase_18 AC 56 ms
13,888 KB
testcase_19 AC 67 ms
14,656 KB
testcase_20 AC 26 ms
11,328 KB
testcase_21 AC 78 ms
15,168 KB
testcase_22 AC 9 ms
9,792 KB
testcase_23 AC 3 ms
9,152 KB
testcase_24 AC 3 ms
9,152 KB
testcase_25 AC 4 ms
9,152 KB
testcase_26 AC 3 ms
9,152 KB
testcase_27 AC 3 ms
9,152 KB
testcase_28 AC 89 ms
16,624 KB
testcase_29 AC 118 ms
24,000 KB
testcase_30 AC 3 ms
9,152 KB
testcase_31 AC 3 ms
9,152 KB
testcase_32 AC 4 ms
9,152 KB
testcase_33 AC 3 ms
9,152 KB
testcase_34 AC 3 ms
9,152 KB
testcase_35 AC 4 ms
9,152 KB
testcase_36 AC 4 ms
9,152 KB
testcase_37 AC 4 ms
9,152 KB
testcase_38 AC 3 ms
9,152 KB
testcase_39 AC 4 ms
9,152 KB
testcase_40 AC 5 ms
9,280 KB
testcase_41 AC 6 ms
9,408 KB
testcase_42 AC 8 ms
9,664 KB
testcase_43 AC 12 ms
10,176 KB
testcase_44 AC 26 ms
11,072 KB
testcase_45 AC 43 ms
12,992 KB
testcase_46 AC 93 ms
16,064 KB
testcase_47 AC 98 ms
16,192 KB
testcase_48 AC 95 ms
16,192 KB
testcase_49 AC 98 ms
16,192 KB
testcase_50 AC 26 ms
12,156 KB
testcase_51 AC 5 ms
9,408 KB
testcase_52 AC 56 ms
15,344 KB
testcase_53 AC 52 ms
14,960 KB
testcase_54 AC 5 ms
9,408 KB
testcase_55 AC 83 ms
16,612 KB
testcase_56 AC 75 ms
16,544 KB
testcase_57 AC 73 ms
16,648 KB
testcase_58 AC 72 ms
16,620 KB
testcase_59 AC 74 ms
16,616 KB
testcase_60 AC 63 ms
16,192 KB
testcase_61 AC 64 ms
16,320 KB
testcase_62 AC 65 ms
18,496 KB
testcase_63 AC 69 ms
22,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
vector<int> E[202020];
int dp[202020][2];
int ret;

void dfs(int cur,int pre) {
	dp[cur][1]=1;
	FORR(e,E[cur]) if(e!=pre) {
		dfs(e,cur);
		dp[cur][1]+=dp[e][0];
		dp[cur][0]+=max(dp[e][0],dp[e][1]);
	}
}

void dfs2(int cur,int pre,int dp0,int dp1) {
	dp[cur][1]+=dp0;
	dp[cur][0]+=max(dp1,dp0);
	
	ret=min(ret,dp[cur][1]);
	
	FORR(e,E[cur]) if(e!=pre) {
		dfs2(e,cur,dp[cur][0]-max(dp[e][0],dp[e][1]),dp[cur][1]-dp[e][0]);
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	ret=N;
	dfs(0,0);
	dfs2(0,0,0,0);
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0