結果

問題 No.1215 都市消滅ビーム
ユーザー autumn-eelautumn-eel
提出日時 2020-08-29 15:05:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,073 bytes
コンパイル時間 5,650 ms
コンパイル使用メモリ 166,904 KB
実行使用メモリ 814,612 KB
最終ジャッジ日時 2023-08-09 11:07:14
合計ジャッジ時間 4,988 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 RE -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 RE -
testcase_12 WA -
testcase_13 MLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int K;
vector<int>E[200000];
int c[200000];
int l[200000],r[200000];

int dep[200000];
int node_cnt;
int vid[200000];
int vin[200000],vout[200000];

void dfs_euler(int v,int p){
	vid[v]=vin[v]=node_cnt++;
	for(int u:E[v]){
		if(u==p)continue;
		dep[u]=dep[v]+1;
		dfs_euler(u,v);
	}
	vout[v]=node_cnt;
}

int ans=0;

void dfs(int v,int p){
	int L=-1,R=K;
	for(int u:E[v]){
		if(u==p)continue;
		dfs(u,v);
		L=max(L,l[u]);
		R=min(R,r[u]);
	}
	L=min(L,R-1);
	while(L+1<R&&vin[v]<=vid[c[L+1]]&&vid[c[L+1]]<vout[v])L++;
	while(R-1>L&&vin[v]<=vid[c[R-1]]&&vid[c[R-1]]<vout[v])R--;
	if(L+1+(K-R)){
		ans=max(ans,L+1+(K-R)+dep[v]);
	}
	l[v]=L;r[v]=R;
}

int main(){
	int n;
	cin>>n>>K;
	rep(i,K)scanf("%d",&c[i]);
	rep(i,n-1){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	dfs_euler(0,-1);
	dfs(0,-1);
	cout<<ans<<endl;
}
0