Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:一直Runtime Error,也不知道为啥?求大佬解答

Posted by zhaoxp at 2019-07-31 16:15:54 on Problem 2631
In Reply To:一直Runtime Error,也不知道为啥?求大佬解答 Posted by:zhaoxp at 2019-07-31 16:13:16
> #include<cstdio>
> #include<cstring>
> #include<vector>
> #include<queue>
> #include<algorithm>
> using namespace std;
> const int maxn=1e4+7;
> 
> struct edge
> {
> 	int to, cost;
> };
> vector<edge> g[maxn];
> queue<int> que;
> int vis[maxn];
> int dis[maxn];
> int bfs(int s, int flag)
> {
> 	memset(vis, 0, sizeof(vis));
> 	memset(dis, 0, sizeof(dis));
> 	edge e;
> 	int tmp=0, tmpi, u;
> 	vis[s]=1;
> 	dis[s]=0;
> 	que.push(s);
> 	while(!que.empty())
> 	{
> 		u=que.front();
> 		que.pop();
> 		for(int i=0; i<g[u].size(); i++)
> 		{
> 			e=g[u][i];
> 			if(vis[e.to]==0)
> 			{
> 				vis[e.to]=1;
> 				dis[e.to]=dis[u]+e.cost;
> 				if(tmp < dis[e.to])
> 				{
> 					tmp=dis[e.to];
> 					tmpi=e.to;
> 				}
> 				que.push(e.to);
> 			}
> 		}
> 	}
> 	if(flag==0) return tmpi;
> 	else return tmp;
> }
> int main()
> {
> 	int a, b, c, ans=0;
> 	edge e;
> 	while(scanf("%d%d%d", &a, &b, &c)!=EOF)
> 	{
> 		e.cost=c;
> 		e.to=b;
> 		g[a].push_back(e);
> 		e.to=a;
> 		g[b].push_back(e);
> 	}
> 	a=bfs(1, 0); //这里任意选了一个点 
> 	ans=bfs(a, 1);
> 	printf("%d\n", ans);
> 	return 0;
>  } 

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator