Submission #2100594


Source Code Expand

    #include<bits/stdc++.h>
    using namespace std ; 
    const int MAXN = 2000 + 100 ; 
     
    int n , k , res  , dp[MAXN] , ans = MAXN; 
    vector<int>adj[MAXN] ; 
     
    void dfs(int u , int par=-1 , int h=0 )
    {
    	if(h>(k/2))
    		res++ ;
    	if(k%2 == 1 && h == (k/2)+1)
    		dp[u] ++ ; 
    	
    	for(auto v : adj[u])
    	{
    		if(v == par)
    			continue ; 
    		dfs(v , u , h+1) ; 
    		dp[u] += dp[v] ; 
    	}
    }
     
    int main()
    {
    	cin >> n >> k ; 
    	for(int i=0 ; i<n-1 ; i++)
    	{
    		int u , v ; 
    		cin >> u >> v ; 
    		u-- , v-- ;
    		adj[u].push_back(v) ;
    		adj[v].push_back(u) ; 
    	}
    	
    	for(int i=0 ; i<n  ;i++)
    	{
    		dfs(i) ; 
    		if(k%2 == 1)
    		{
    			int mx = 0  ;
    			for(auto x : adj[i])
    			{
    				mx = max(mx , dp[x]) ;
    			}
    			res-=mx;
    		}
    		ans= min(ans , res) ; 
    		res = 0 ; 
    		for(int j=0 ; j<n ; j++)
    			dp[j] = 0  ; 
    	}
    	cout << ans << endl ; 
    }

Submission Info

Submission Time
Task C - Shorten Diameter
User vjudge4
Language Bash (GNU bash v4.3.11)
Score 0
Code Size 1008 Byte
Status RE
Exec Time 148 ms
Memory 1692 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
RE × 2
RE × 34
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, sample-01.txt, sample-02.txt
Case Name Status Exec Time Memory
000.txt RE 148 ms 1692 KB
001.txt RE 4 ms 652 KB
002.txt RE 4 ms 548 KB
003.txt RE 4 ms 552 KB
004.txt RE 4 ms 648 KB
005.txt RE 4 ms 544 KB
006.txt RE 4 ms 548 KB
007.txt RE 4 ms 552 KB
008.txt RE 4 ms 544 KB
009.txt RE 4 ms 548 KB
010.txt RE 4 ms 548 KB
011.txt RE 4 ms 644 KB
012.txt RE 4 ms 552 KB
013.txt RE 4 ms 544 KB
014.txt RE 4 ms 548 KB
015.txt RE 4 ms 540 KB
016.txt RE 4 ms 544 KB
017.txt RE 4 ms 552 KB
018.txt RE 3 ms 548 KB
019.txt RE 4 ms 540 KB
020.txt RE 4 ms 540 KB
021.txt RE 4 ms 648 KB
022.txt RE 4 ms 544 KB
023.txt RE 4 ms 544 KB
024.txt RE 4 ms 544 KB
025.txt RE 4 ms 540 KB
026.txt RE 4 ms 648 KB
027.txt RE 4 ms 540 KB
028.txt RE 4 ms 544 KB
029.txt RE 3 ms 548 KB
030.txt RE 4 ms 552 KB
031.txt RE 3 ms 548 KB
sample-01.txt RE 3 ms 552 KB
sample-02.txt RE 3 ms 544 KB