General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
52524405 Practice:
nsut_coder
120F - 41 C++14 (GCC 6-32) Runtime error on test 1 30 ms 0 KB 2019-04-09 13:44:16 2019-04-09 13:44:16
→ Source
#include<bits/stdc++.h>
using namespace std; 
int temp=0;

void dfs(int node,int p,vector<int>adj[],int dp1[],int dp2[]){

	int mx1=-1,mx2=-1;

	for(auto u:adj[node]){
		if(u==p ) continue; 

		dfs(u,node,adj,dp1,dp2);

		if(dp1[u]>=mx1){
			mx2=mx1;
			mx1=dp1[u];			 
		}else if(dp1[u]>mx2){
			mx2=dp1[u];
		}
	}

	dp1[node]=1; 

	if(mx1!=-1) dp1[node]+=mx1; 

	dp2[node]=dp1[node];

	if(mx2!=-1) dp2[node]+=mx2; 

	temp=max(temp,dp2[node]);
}

int main(){
	int t; cin>>t;
	int ans=0;
	while(t--){
		int n; cin>>n;
		vector<int>adj[n+1];
		for(int i=1;i<n;i++){
			int x,y; cin>>x>>y; 
			adj[x].push_back(y);
			adj[y].push_back(x);
		} 

		int dp1[n+1],dp2[n+1];

		memset(dp1,0,sizeof(dp1));

		memset(dp2,0,sizeof(dp2));

		dfs(1,0,adj,dp1,dp2);

		ans+=temp-1; 

		temp=0;

	}
	cout<<ans<<endl;

}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details