Who can help me?

Правка en1, от jimmy_hu, 2016-01-30 17:10:36

I have some problem with my code.It can accept the simple data.but I got wrong answer on test 3.So who can help me?

This is my code.

include

include

include

include

include

include

include

include

include

include

include

include

include

include

include

include

include

include

include

include

using namespace std;

vector< long long > graph[200022]; bool visit[200022]; long long n;

long long dfs(long long v) { visit[v]=true; for (long long it=*graph[v].begin();it!=*graph[v].end();++it) { if (!visit[it]) { return dfs(it)+1; } } return 0; }

int main() { long long treev,roadv; cin>>n>>treev>>roadv; for(long long i=1;i<n;i++) { long long x,y; cin>>x>>y; graph[x].push_back(y);
graph[y].push_back(x); } long long maxn=0,t=0,minn=200000000; for(long long i=1;i<=n;i++) { if(graph[i].size()==1) { memset(visit,0,sizeof(visit)); t=dfs(i); cout<<i<<" "<<t<<endl; } maxn=max(maxn,t); minn=min(minn,t); }

if(treev<roadv) 
    cout<<(maxn*treev+(n-maxn-1)*roadv);
else
    cout<<(minn*treev+(n-minn-1)*roadv);

return 0;

}

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский jimmy_hu 2016-01-30 17:11:10 22
en1 Английский jimmy_hu 2016-01-30 17:10:36 1396 Initial revision (published)