Submission #808378


Source Code Expand

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Foreach(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define rof(i,a,b) for(int (i)=(a);(i) > (b); --(i))
#define rep(i, c) for(auto &(i) : (c))
#define x first
#define y second
#define pb push_back
#define PB pop_back()
#define iOS ios_base::sync_with_stdio(false)
#define sqr(a) (((a) * (a)))
#define all(a) a.begin() , a.end()
#define error(x) cerr << #x << " = " << (x) <<endl
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define errop(a) cerr<<#a<<" = ( "<<((a).x)<<" , "<<((a).y)<<" )\n";
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)
#define umap unordered_map
#define double long double
typedef long long ll;
typedef pair<int,int>pii;
typedef vector<int> vi;
typedef complex<double> point;
template <typename T> using os =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}
const int maxn = 2100;
vi adj[maxn];
int cnt = 0, ans = 0;
int dp[maxn][maxn], sz[maxn], odp[maxn][maxn];
int n, k;
inline void dfs(int v = 0, int p = -1){
	sz[v] = 1;
	For(i,0,n+1)	smax(dp[v][i], 1);
	rep(u, adj[v])	if(u - p){
		dfs(u, v);
		For(i,0,sz[v] + 1)	odp[v][i] = dp[v][i];
		rof(i,sz[v],-1)
			For(j,0,sz[u]+1)if(i + j + 1 <= k)
				smax(dp[v][max(i, j+1)], odp[v][i] + dp[u][j]);
		sz[v] += sz[u];
	}
	For(i,1,n+1)	smax(dp[v][i], dp[v][i-1]);
}
int main(){
	iOS;
	cin >> n >> k;
	For(i,1,n){
		int v, u;
		cin >> v >> u;
		-- v, -- u;
		adj[v].pb(u), adj[u].pb(v);
	}
	dfs(0);
	For(i,0,n)	smax(ans, dp[i][k]);
	cout << n-ans << endl;
	return 0;
}

Submission Info

Submission Time
Task C - Shorten Diameter
User amd
Language C++14 (GCC 5.4.1)
Score 600
Code Size 2000 Byte
Status AC
Exec Time 108 ms
Memory 24832 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 2
AC × 32
Set Name Test Cases
Sample sample-01.txt, sample-02.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt
Case Name Status Exec Time Memory
000.txt AC 4 ms 256 KiB
001.txt AC 4 ms 384 KiB
002.txt AC 4 ms 384 KiB
003.txt AC 4 ms 384 KiB
004.txt AC 4 ms 384 KiB
005.txt AC 4 ms 384 KiB
006.txt AC 4 ms 384 KiB
007.txt AC 4 ms 384 KiB
008.txt AC 4 ms 384 KiB
009.txt AC 84 ms 22016 KiB
010.txt AC 81 ms 17024 KiB
011.txt AC 89 ms 20864 KiB
012.txt AC 86 ms 22016 KiB
013.txt AC 79 ms 17024 KiB
014.txt AC 81 ms 20736 KiB
015.txt AC 86 ms 22144 KiB
016.txt AC 80 ms 17024 KiB
017.txt AC 85 ms 20864 KiB
018.txt AC 12 ms 2944 KiB
019.txt AC 6 ms 1152 KiB
020.txt AC 35 ms 10240 KiB
021.txt AC 69 ms 18688 KiB
022.txt AC 34 ms 7936 KiB
023.txt AC 10 ms 2432 KiB
024.txt AC 28 ms 7424 KiB
025.txt AC 8 ms 1664 KiB
026.txt AC 72 ms 18816 KiB
027.txt AC 91 ms 24832 KiB
028.txt AC 108 ms 24832 KiB
029.txt AC 95 ms 24832 KiB
030.txt AC 90 ms 16768 KiB
031.txt AC 96 ms 16768 KiB
sample-01.txt AC 4 ms 384 KiB
sample-02.txt AC 4 ms 384 KiB