各位大神能幫我看一下程式碼哪裡有問題嗎?
我只拿到65%
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <stack>
#define Max 100001
using std::cin;
using std::cout;
using std::endl;
using std::stack;
using std::vector;
int height[Max];
vector<int> edge[Max];
stack<int> leaf;
/*
int re_dfs(int node){
if (edge[node].size()==0) return 0;
int fnode = edge[node][0];
if(height[node]+1<height[fnode]) return 0;
height[fnode] = height[node]+1;
re_dfs(fnode);
}
*/
int main(){
int N,n=0;
while (cin>>N){
//Initalization
for(int i=0;i<N;i++){
edge[i].clear();
height[i] = 0;
}
//Reciving Tesing context
for(int i = 1;i<N+1;i++){
cin>>n;
for(int j = 0,temp;j<n;j++){
cin>>temp,edge[temp].push_back(i);
}
if (n==0) leaf.push(i);
}
//Start with leaf
while(!leaf.empty()){
int node = leaf.top();
leaf.pop();
while(edge[node].size() != 0){
int fnode = edge[node][0];
if(height[node]+1 >height[fnode]) height[fnode] = height[node]+1;
node = fnode;
}
}
int index = 0,sum = 0,max_height=height[0];
for(int i = 1;i<N;i++){
sum+=height[i];
if(height[i]>max_height) index=i,max_height = height[i];
}
cout << index << endl << sum<<endl;
}
}