結果

問題 No.2677 Minmax Independent Set
ユーザー kotatsugamekotatsugame
提出日時 2024-03-15 22:27:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 845 bytes
コンパイル時間 704 ms
コンパイル使用メモリ 70,972 KB
実行使用メモリ 30,400 KB
最終ジャッジ日時 2024-03-15 22:27:50
合計ジャッジ時間 7,330 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,944 KB
testcase_01 AC 4 ms
10,944 KB
testcase_02 AC 4 ms
11,072 KB
testcase_03 AC 5 ms
10,944 KB
testcase_04 AC 5 ms
10,944 KB
testcase_05 AC 122 ms
19,136 KB
testcase_06 AC 120 ms
19,392 KB
testcase_07 AC 123 ms
19,520 KB
testcase_08 AC 122 ms
19,776 KB
testcase_09 AC 127 ms
20,288 KB
testcase_10 AC 97 ms
18,440 KB
testcase_11 AC 96 ms
18,316 KB
testcase_12 AC 155 ms
30,400 KB
testcase_13 AC 142 ms
22,280 KB
testcase_14 AC 133 ms
22,376 KB
testcase_15 AC 154 ms
24,860 KB
testcase_16 AC 149 ms
18,112 KB
testcase_17 AC 139 ms
18,112 KB
testcase_18 AC 74 ms
15,808 KB
testcase_19 AC 91 ms
16,576 KB
testcase_20 AC 27 ms
13,120 KB
testcase_21 AC 108 ms
17,088 KB
testcase_22 AC 10 ms
11,584 KB
testcase_23 AC 5 ms
11,072 KB
testcase_24 AC 5 ms
11,072 KB
testcase_25 AC 5 ms
11,072 KB
testcase_26 AC 5 ms
11,072 KB
testcase_27 AC 5 ms
11,072 KB
testcase_28 AC 86 ms
18,504 KB
testcase_29 AC 148 ms
25,792 KB
testcase_30 AC 5 ms
10,944 KB
testcase_31 AC 5 ms
10,944 KB
testcase_32 AC 5 ms
11,072 KB
testcase_33 AC 5 ms
11,072 KB
testcase_34 AC 5 ms
11,072 KB
testcase_35 AC 5 ms
11,072 KB
testcase_36 AC 5 ms
11,072 KB
testcase_37 AC 5 ms
11,072 KB
testcase_38 AC 5 ms
11,072 KB
testcase_39 AC 5 ms
11,072 KB
testcase_40 AC 6 ms
11,200 KB
testcase_41 AC 7 ms
11,200 KB
testcase_42 AC 9 ms
11,456 KB
testcase_43 AC 15 ms
11,968 KB
testcase_44 AC 27 ms
12,992 KB
testcase_45 AC 60 ms
14,784 KB
testcase_46 AC 149 ms
17,984 KB
testcase_47 AC 142 ms
17,984 KB
testcase_48 AC 145 ms
17,984 KB
testcase_49 AC 149 ms
18,112 KB
testcase_50 AC 33 ms
14,036 KB
testcase_51 AC 6 ms
11,328 KB
testcase_52 AC 76 ms
17,224 KB
testcase_53 AC 69 ms
16,840 KB
testcase_54 AC 6 ms
11,200 KB
testcase_55 AC 99 ms
18,492 KB
testcase_56 AC 106 ms
18,424 KB
testcase_57 AC 103 ms
18,528 KB
testcase_58 AC 100 ms
18,500 KB
testcase_59 AC 103 ms
18,496 KB
testcase_60 AC 66 ms
18,112 KB
testcase_61 AC 73 ms
18,240 KB
testcase_62 AC 69 ms
20,416 KB
testcase_63 AC 74 ms
24,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cassert>
using namespace std;
int N;
vector<int>G[2<<17];
int dp[2<<17][2];
void dfs(int u,int p)
{
	if(p!=-1)
	{
		int i=0;
		while(G[u][i]!=p)i++;
		if(i+1<G[u].size())swap(G[u][i],G[u][G[u].size()-1]);
		G[u].pop_back();
	}
	dp[u][0]=0;
	dp[u][1]=1;
	for(int v:G[u])
	{
		dfs(v,u);
		dp[u][0]+=max(dp[v][0],dp[v][1]);
		dp[u][1]+=dp[v][0];
	}
}
int ans=1e9;
void dfs2(int u,int pdp0,int pdp1)
{
	int now=pdp0;
	dp[u][0]+=max(pdp0,pdp1);
	dp[u][1]+=pdp0;
	for(int v:G[u])
	{
		now+=dp[v][0];
		dfs2(v,dp[u][0]-max(dp[v][0],dp[v][1]),dp[u][1]-dp[v][0]);
	}
	ans=min(ans,now+1);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N;
	for(int i=1;i<N;i++)
	{
		int u,v;cin>>u>>v;
		u--,v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(0,-1);
	dfs2(0,0,0);
	cout<<ans<<endl;
}
0