jimmy_hu's blog

By jimmy_hu, history, 9 years ago, In English

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;

}

Full text and comments »

  • Vote: I like it
  • -16
  • Vote: I do not like it