pat甲级dijkstra算法综合合集

1003 Emergency (25分)
As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked on the map. When there is an emergency call to you from some other city, your job is to lead your men to the place as quickly as possible, and at the mean time, call up as many hands on the way as possible.

Input Specification:
Each input file contains one test case. For each test case, the first line contains 4 positive integers: N (≤500) - the number of cities (and the cities are numbered from 0 to N−1), M - the number of roads, C
​1
​​ and C
​2
​​ - the cities that you are currently in and that you must save, respectively. The next line contains N integers, where the i-th integer is the number of rescue teams in the i-th city. Then M lines follow, each describes a road with three integers c
​1
​​ , c
​2
​​ and L, which are the pair of cities connected by a road and the length of that road, respectively. It is guaranteed that there exists at least one path from C
​1
​​ to C
​2
​​ .

Output Specification:
For each test case, print in one line two numbers: the number of different shortest paths between C
​1
​​ and C
​2
​​ , and the maximum amount of rescue teams you can possibly gather. All the numbers in a line must be separated by exactly one space, and there is no extra space allowed at the end of a line.

Sample Input:
5 6 0 2
1 2 1 5 3
0 1 1
0 2 2
0 3 1
1 2 1
2 4 1
3 4 1
Sample Output:
2 4
代码:

#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 510
#define inf 99999999
int main(){
	int n,m,s,t;
	int dis[maxn],e[maxn][maxn],weight[maxn],w[maxn],num[maxn];
	bool visit[maxn]={false};
	while(cin>>n>>m>>s>>t){
		fill(dis,dis+510,inf);
		fill(e[0],e[0]+510*510,inf);
		dis[s]=0;
		num[s]=1;
		for(int i=0;i<n;i++){			
			cin>>weight[i];
		}
		w[s]=weight[s];
		int c,d,f;
		for(int i=0;i<m;i++){
			cin>>c>>d>>f;
			e[c][d]=e[d][c]=f;
		}
		for(int i=0;i<n;i++){
			int u=-1,minn=inf;
			for(int j=0;j<n;j++){
				if(!visit[j]&&dis[j]<minn){
					u=j;
					minn=dis[j];
				}
			}
			if(u==-1)  break;
			visit[u]=true;
			for(int i=0;i<n;i++){
				if(!visit[i]&&e[u][i]!=inf){
					if(dis[u]+e[u][i]<dis[i]){
						dis[i]=dis[u]+e[u][i];
						num[i]=num[u];
						w[i]=w[u]+weight[i];
					}else if(dis[u]+e[u][i]==dis[i]){
						num[i]+=num[u];
						if(w[i]<weight[i]+w[u])
						w[i]=weight[i]+w[u];
					} 
				}
			}
		} 
		cout<<num[t]<<" "<<w[t]<<endl;
	}

	return 0;
}

1018 Public Bike Management (30分)
There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and return it to any other stations in the city.

The Public Bike Management Center (PBMC) keeps monitoring the real-time capacity of all the stations. A station is said to be in perfect condition if it is exactly half-full. If a station is full or empty, PBMC will collect or send bikes to adjust the condition of that station to perfect. And more, all the stations on the way will be adjusted as well.

When a problem station is reported, PBMC will always choose the shortest path to reach that station. If there are more than one shortest path, the one that requires the least number of bikes sent from PBMC will be chosen.

The above figure illustrates an example. The stations are represented by vertices and the roads correspond to the edges. The number on an edge is the time taken to reach one end station from another. The number written inside a vertex S is the current number of bikes stored at S. Given that the maximum capacity of each station is 10. To solve the problem at S
​3
​​ , we have 2 different shortest paths:

PBMC -> S
​1
​​ -> S
​3
​​ . In this case, 4 bikes must be sent from PBMC, because we can collect 1 bike from S
​1
​​ and then take 5 bikes to S
​3
​​ , so that both stations will be in perfect conditions.

PBMC -> S
​2
​​ -> S
​3
​​ . This path requires the same time as path 1, but only 3 bikes sent from PBMC and hence is the one that will be chosen.

Input Specification:
Each input file contains one test case. For each case, the first line contains 4 numbers: C
​max
​​ (≤100), always an even number, is the maximum capacity of each station; N (≤500), the total number of stations; S
​p
​​ , the index of the problem station (the stations are numbered from 1 to N, and PBMC is represented by the vertex 0); and M, the number of roads. The second line contains N non-negative numbers C
​i
​​ (i=1,⋯,N) where each C
​i
​​ is the current number of bikes at S
​i
​​ respectively. Then M lines follow, each contains 3 numbers: S
​i
​​ , S
​j
​​ , and T
​ij
​​ which describe the time T
​ij
​​ taken to move betwen stations S
​i
​​ and S
​j
​​ . All the numbers in a line are separated by a space.

Output Specification:
For each test case, print your results in one line. First output the number of bikes that PBMC must send. Then after one space, output the path in the format: 0−>S
​1
​​ −>⋯−>S
​p
​​ . Finally after another space, output the number of bikes that we must take back to PBMC after the condition of S
​p
​​ is adjusted to perfect.

Note that if such a path is not unique, output the one that requires minimum number of bikes that we must take back to PBMC. The judge’s data guarantee that such a path is unique.

Sample Input:
10 3 3 5
6 7 0
0 1 1
0 2 1
0 3 3
1 3 1
2 3 1
Sample Output:
3 0->2->3 0
代码:

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int inf = 99999999;
int cmax, n, sp, m;
int minn = inf, minb = inf;
int e[510][510], dis[510], weight[510];
bool visit[510];
vector<int> pre[510], path, temppath;
void dfs(int v) {
    temppath.push_back(v);
    if(v == 0) {
        int need = 0, back = 0;
        for(int i = temppath.size() - 1; i >= 0; i--) {
            int id = temppath[i];
            if(weight[id] > 0) {
                back += weight[id];
            } else {
                if(back > (0 - weight[id])) {
                    back += weight[id];
                } else {
                    need += ((0 - weight[id]) - back);
                    back = 0;
                }
            }
        }
        if(need < minn) {
            minn = need;
            minb = back;
            path = temppath;
        } else if(need == minn && back < minb) {
            minb = back;
            path = temppath;
        }
        temppath.pop_back();
        return ;
    }
    for(int i = 0; i < pre[v].size(); i++)
        dfs(pre[v][i]);
    temppath.pop_back();
}
int main() {
    fill(e[0], e[0] + 510 * 510, inf);
    fill(dis, dis + 510, inf);
    scanf("%d%d%d%d", &cmax, &n, &sp, &m);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &weight[i]);
        weight[i] = weight[i] - cmax / 2;
    }
    for(int i = 0; i < m; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        scanf("%d", &e[a][b]);
        e[b][a] = e[a][b];
    }
    dis[0] = 0;
    for(int i = 0; i <= n; i++) {
        int u = -1, minn = inf;
        for(int j = 0; j <= n; j++) {
            if(visit[j] == false && dis[j] < minn) {
                u = j;
                minn = dis[j];
            }
        }
        if(u == -1) break;
        visit[u] = true;
        for(int v = 0; v <= n; v++) {
            if(visit[v] == false && e[u][v] != inf) {
                if(dis[v] > dis[u] + e[u][v]) {
                    dis[v] = dis[u] + e[u][v];
                    pre[v].clear();
                    pre[v].push_back(u);
                }else if(dis[v] == dis[u] + e[u][v]) {
                    pre[v].push_back(u);
                }
            }
        }
    }
    dfs(sp);
    printf("%d 0", minn);
    for(int i = path.size() - 2; i >= 0; i--)
        printf("->%d", path[i]);
    printf(" %d", minb);
    return 0;
}

1030 Travel Plan (30分)
A traveler’s map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path between his/her starting city and the destination. If such a shortest path is not unique, you are supposed to output the one with the minimum cost, which is guaranteed to be unique.

Input Specification:
Each input file contains one test case. Each case starts with a line containing 4 positive integers N, M, S, and D, where N (≤500) is the number of cities (and hence the cities are numbered from 0 to N−1); M is the number of highways; S and D are the starting and the destination cities, respectively. Then M lines follow, each provides the information of a highway, in the format:

City1 City2 Distance Cost
where the numbers are all integers no more than 500, and are separated by a space.

Output Specification:
For each test case, print in one line the cities along the shortest path from the starting point to the destination, followed by the total distance and the total cost of the path. The numbers must be separated by a space and there must be no extra space at the end of output.

Sample Input:
4 5 0 3
0 1 1 20
1 3 2 30
0 3 4 10
0 2 2 20
2 3 1 20
Sample Output:
0 2 3 3 40
代码:

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define maxn 510
#define inf 99999999 
int dis[maxn];
vector<int> pre[maxn],temppath,path;
int cost[maxn][maxn],dist[maxn][maxn];
bool visit[maxn];
int mincostsum=inf;
void dfs(int end,int start){
	temppath.push_back(end);
	if(end==start){
	int costsum=0;
	for(int i=temppath.size()-1;i>=1;i--)
		costsum+=cost[temppath[i]][temppath[i-1]];
	if(mincostsum>costsum){
		mincostsum=costsum;
		path=temppath;
	}
	temppath.pop_back();
	return; 
	}
	for(int i=0;i<pre[end].size();i++){
		dfs(pre[end][i],start);
	}
	temppath.pop_back();
}
int main(){
	fill(dis,dis+maxn,inf);
	fill(cost[0],cost[0]+maxn*maxn,inf);
	fill(dist[0],dist[0]+maxn*maxn,inf);
	int n,m,s,d,x,y,distance,costs;
	scanf("%d%d%d%d",&n,&m,&s,&d);
	for(int i=0;i<m;i++){
		scanf("%d%d%d%d",&x,&y,&distance,&costs);
		cost[x][y]=cost[y][x]=costs;
		dist[x][y]=dist[y][x]=distance;
	}
	dis[s]=0;
	for(int i=0;i<n;i++){
		int minn=inf,u=-1;
		for(int j=0;j<n;j++){
			if(visit[j]==false&&dis[j]<minn){
				minn=dis[j];
				u=j;
			}
		}
		if(u==-1) break;
		visit[u]=true;
		for(int v=0;v<n;v++){
			if(dist[u][v]!=inf&&visit[v]==false){
				if(dis[v]>dis[u]+dist[u][v]){
					dis[v]=dis[u]+dist[u][v];
					pre[v].clear();
					pre[v].push_back(u);
				}else if(dis[v]==dis[u]+dist[u][v]){
					pre[v].push_back(u);
				}
			}
		}
	}
	dfs(d,s);
	for(int i=path.size()-1;i>=0;i--)
	printf("%d ",path[i]);	
	printf("%d %d",dis[d],mincostsum);
}

1072 Gas Station (30分)
A gas station has to be built at such a location that the minimum distance between the station and any of the residential housing is as far away as possible. However it must guarantee that all the houses are in its service range.

Now given the map of the city and several candidate locations for the gas station, you are supposed to give the best recommendation. If there are more than one solution, output the one with the smallest average distance to all the houses. If such a solution is still not unique, output the one with the smallest index number.

Input Specification:
Each input file contains one test case. For each case, the first line contains 4 positive integers: N (≤10
​3
​​ ), the total number of houses; M (≤10), the total number of the candidate locations for the gas stations; K (≤10
​4
​​ ), the number of roads connecting the houses and the gas stations; and D
​S
​​ , the maximum service range of the gas station. It is hence assumed that all the houses are numbered from 1 to N, and all the candidate locations are numbered from G1 to GM.

Then K lines follow, each describes a road in the format

P1 P2 Dist
where P1 and P2 are the two ends of a road which can be either house numbers or gas station numbers, and Dist is the integer length of the road.

Output Specification:
For each test case, print in the first line the index number of the best location. In the next line, print the minimum and the average distances between the solution and all the houses. The numbers in a line must be separated by a space and be accurate up to 1 decimal place. If the solution does not exist, simply output No Solution.

Sample Input 1:
4 3 11 5
1 2 2
1 4 2
1 G1 4
1 G2 3
2 3 2
2 G2 1
3 4 2
3 G3 2
4 G1 3
G2 G1 1
G3 G2 2
Sample Output 1:
G1
2.0 3.3
Sample Input 2:
2 1 2 10
1 G1 9
2 G1 20
Sample Output 2:
No Solution
代码:

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define maxn 1020
#define inf 99999999
int cost[maxn][maxn];
int dis[maxn];
bool visit[maxn];
int ansid;
double mindis=0,aver;
int main(){
	int n,m,s,t,d;
	string j,k;
	fill(dis,dis+maxn,inf);
	fill(cost[0],cost[0]+maxn*maxn,inf);
	scanf("%d%d%d%d",&n,&m,&s,&t);
	for(int i=0;i<s;i++){
		cin>>j>>k>>d;
		int a,b;
		if(j[0]=='G'){
			string u=j.substr(1);
			 a=n+stoi(u);
		}else{
			 a=stoi(j);
		}
		if(k[0]=='G'){
			string u=k.substr(1);
			 b=n+stoi(u);
		}else{
			 b=stoi(k);
		}
	 cost[a][b]=cost[b][a]=d;	
	}
	double ansdis=0;
	double aversum=0;
	int ansid=-1;
	double ansaver=-1;
	for(int i=n+1;i<=n+m;i++){
		mindis=inf; 
		aver=0;
		fill(visit,visit+maxn,false);
		fill(dis,dis+maxn,inf);
		dis[i]=0;
		for(int j=1;j<=n+m;j++){
			int minn=inf,u=-1;
			for(int k=1;k<=n+m;k++){
				if(dis[k]<minn&&visit[k]==false){
					minn=dis[k];
					u=k;
				}
			}
			if(u==-1) break;
			visit[u]=true;
			for(int v=1;v<=n+m;v++){
			  	if(visit[v]==false&&cost[u][v]!=inf){
			  		if(dis[v]>dis[u]+cost[u][v])
			  		dis[v]=dis[u]+cost[u][v];
				  }
			}
		}
		for(int h=1;h<=n;h++){
			aver+=1.0*dis[h];
			if(dis[h]>t){
				mindis=-1;
				break;
			}			
			if(dis[h]<mindis)
			mindis=dis[h];	
		} 
		if(mindis==-1)  
		continue;
		aver=aver*1.0/n;	   
	    if(mindis>ansdis){
	    	ansdis=mindis;
            ansid=i; 
			ansaver=aver;
		}else if(mindis==ansdis&&aver<ansaver){
			ansid=i;
			ansaver=aver;
		}
	}
	printf("G%d\n",ansid-n);
	printf("%.1f %.1f",ansdis,ansaver);
}

题目有点bug,测试用例有错。
1087 All Roads Lead to Rome (30分)
Indeed there are many different tourist routes from our city to Rome. You are supposed to find your clients the route with the least cost while gaining the most happiness.

Input Specification:
Each input file contains one test case. For each case, the first line contains 2 positive integers N (2≤N≤200), the number of cities, and K, the total number of routes between pairs of cities; followed by the name of the starting city. The next N−1 lines each gives the name of a city and an integer that represents the happiness one can gain from that city, except the starting city. Then K lines follow, each describes a route between two cities in the format City1 City2 Cost. Here the name of a city is a string of 3 capital English letters, and the destination is always ROM which represents Rome.

Output Specification:
For each test case, we are supposed to find the route with the least cost. If such a route is not unique, the one with the maximum happiness will be recommanded. If such a route is still not unique, then we output the one with the maximum average happiness – it is guaranteed by the judge that such a solution exists and is unique.

Hence in the first line of output, you must print 4 numbers: the number of different routes with the least cost, the cost, the happiness, and the average happiness (take the integer part only) of the recommanded route. Then in the next line, you are supposed to print the route in the format City1->City2->…->ROM.

Sample Input:
6 7 HZH
ROM 100
PKN 40
GDN 55
PRS 95
BLN 80
ROM GDN 1
BLN ROM 1
HZH PKN 1
PRS ROM 2
BLN HZH 2
PKN GDN 1
HZH PRS 1
Sample Output:
3 3 195 97
HZH->PRS->ROM
作者
CHEN, Yue
单位
浙江大学
代码长度限制
16 KB
时间限制
200 ms
内存限制
64 MB
代码:

#include<iostream>
#include<map>
#include<vector>
#include<algorithm> 
using namespace std;
#define maxn 202
#define inf 99999999
vector<int> pre[maxn],path,temppath;
map<string, int> m1;
map<int, string> m2;
bool visit[maxn];
int dis[maxn];
int cost[maxn][maxn];
int weight[maxn];
int maxvalue=0,cntpath=0;
double maxavalue=0;
void dfs(int v){
	temppath.push_back(v);
	if(v==1){
		int value=0;
		for(int i=0;i<temppath.size();i++){
			value+=weight[temppath[i]];
		}
		double  avalue=value*1.0/(temppath.size()-1);
		if(maxvalue<value){
			maxvalue=value;
			maxavalue=avalue;
			path=temppath;
		}else if(maxvalue==value&&maxavalue<avalue){
			maxavalue=avalue;
			path=temppath;
		}
		temppath.pop_back();
		cntpath++;
		return;
	}
	for(int i=0;i<pre[v].size();i++){
		dfs(pre[v][i]);
	}
	temppath.pop_back();
}
int main(){
	fill(dis,dis+maxn,inf);
	fill(cost[0],cost[0]+maxn*maxn,inf);
	int n,m;
	string s;
	scanf("%d %d",&n,&m);
	cin>>s;
	m1[s]=1;
	m2[1]=s;
	for(int i=0;i<n-1;i++){
		string t;
		int h;
		cin>>t>>h;
		weight[i+2]=h;
		m1[t]=i+2;
		m2[i+2]=t;
	}
	for(int i=0;i<m;i++){
	  string j,k;
	  int g;
	  cin>>j>>k>>g;
	  cost[m1[k]][m1[j]]=cost[m1[j]][m1[k]]=g;
	}
	dis[1]=0;
	for(int i=0;i<n;i++){
		int u=-1,minn=inf;
		for(int j=1;j<=n;j++){
			if(visit[j]==false&&dis[j]<minn){
				minn=dis[j];
				u=j;
			}
		}
		if(u==-1) break;
		visit[u]=true;
		for(int v=1;v<=n;v++){
			if(visit[v]==false&&cost[u][v]!=inf){
				if(dis[v]>dis[u]+cost[u][v]){
					dis[v]=dis[u]+cost[u][v];
					pre[v].clear();
					pre[v].push_back(u);
				}else if(dis[v]==dis[u]+cost[u][v]){
					pre[v].push_back(u);
				} 
			}
		}
	}
	int num=m1["ROM"];
	dfs(num);
	printf("%d %d %d %d\n",cntpath,dis[num],maxvalue,(int)maxavalue);
	for(int i=path.size()-1;i>=1;i--){
		cout<<m2[path[i]]<<"->";
	}
	cout<<"ROM";
}

1111 Online Map (30分)
Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two paths to your user: one is the shortest, and the other is the fastest. It is guaranteed that a path exists for any request.

Input Specification:
Each input file contains one test case. For each case, the first line gives two positive integers N (2≤N≤500), and M, being the total number of streets intersections on a map, and the number of streets, respectively. Then M lines follow, each describes a street in the format:

V1 V2 one-way length time
where V1 and V2 are the indices (from 0 to N−1) of the two ends of the street; one-way is 1 if the street is one-way from V1 to V2, or 0 if not; length is the length of the street; and time is the time taken to pass the street.

Finally a pair of source and destination is given.

Output Specification:
For each case, first print the shortest path from the source to the destination with distance D in the format:

Distance = D: source -> v1 -> … -> destination
Then in the next line print the fastest path with total time T:

Time = T: source -> w1 -> … -> destination
In case the shortest path is not unique, output the fastest one among the shortest paths, which is guaranteed to be unique. In case the fastest path is not unique, output the one that passes through the fewest intersections, which is guaranteed to be unique.

In case the shortest and the fastest paths are identical, print them in one line in the format:

Distance = D; Time = T: source -> u1 -> … -> destination
Sample Input 1:
10 15
0 1 0 1 1
8 0 0 1 1
4 8 1 1 1
3 4 0 3 2
3 9 1 4 1
0 6 0 1 1
7 5 1 2 1
8 5 1 2 1
2 3 0 2 2
2 1 1 1 1
1 3 0 3 1
1 4 0 1 1
9 7 1 3 1
5 1 0 5 2
6 5 1 1 2
3 5
Sample Output 1:
Distance = 6: 3 -> 4 -> 8 -> 5
Time = 3: 3 -> 1 -> 5
Sample Input 2:
7 9
0 4 1 1 1
1 6 1 1 3
2 6 1 1 1
2 5 1 2 2
3 0 0 1 1
3 1 1 1 3
3 2 1 1 2
4 5 0 2 2
6 5 1 1 2
3 5
Sample Output 2:
Distance = 3; Time = 4: 3 -> 2 -> 5
代码:

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define maxn 510
#define inf 99999999
int dis[maxn];
int tim[maxn];
int cost[maxn][maxn];
int ti[maxn][maxn];
vector<int> temppath,temppath2,path1,path2,pre[maxn],pre1[maxn];
bool visit[maxn];
bool visit1[maxn];
int mintimesum=inf,minsum=inf;
void dfs1(int end,int start){
	temppath.push_back(end);
	if(end==start){
		int timesum=0;
		for(int i=temppath.size()-1;i>=1;i--){
			timesum+=ti[temppath[i]][temppath[i-1]];
		}
		if(mintimesum>timesum){
			mintimesum=timesum;	
			path1=temppath;		
		}																		
	   temppath.pop_back();
		return;
	}
	for(int i=0;i<pre[end].size();i++){
		dfs1(pre[end][i],start);
	}
	temppath.pop_back();
}
void dfs2(int end,int start){
	temppath2.push_back(end);	
	if(end==start){
		if(temppath2.size()<minsum){
		   minsum=temppath2.size();
		   path2=temppath2;	
		}
		temppath2.pop_back();
		return;
	}
	for(int i=0;i<pre1[end].size();i++){
		dfs2(pre1[end][i],start);
	}
	temppath2.pop_back();
}
int main(){
	int a,b,x,y, state,length,times;
	fill(dis,dis+maxn,inf);
	fill(tim,tim+maxn,inf);
	fill(cost[0],cost[0]+maxn*maxn,inf);
	fill(ti[0],ti[0]+maxn*maxn,inf);
	scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		scanf("%d%d%d%d%d",&x,&y,&state,&length,&times);
		cost[x][y]=length;
		ti[x][y]=times;
		if(state==0){
			cost[y][x]=length;
			ti[y][x]=times;
		}			
	}
	int start,end;
	scanf("%d%d",&start,&end);
	dis[start]=0;
	for(int i=0;i<a;i++){
		int minn=inf,u=-1;
		for(int j=0;j<a;j++){
			if(visit[j]==false&&dis[j]<minn){
				minn=dis[j];
				u=j;
			}
		}
		if(u==-1) break;
		visit[u]=true;
		for(int v=0;v<a;v++){
			if(visit[v]==false&&cost[u][v]!=inf){
				if(dis[v]>dis[u]+cost[u][v]){
					dis[v]=dis[u]+cost[u][v];
					pre[v].clear();
					pre[v].push_back(u);
				}else if(dis[v]==dis[u]+cost[u][v]){
					pre[v].push_back(u);
				} 
			}
			
		} 
	}
	tim[start]=0;
	for(int i=0;i<a;i++){
		int minn=inf,u=-1;
		for(int j=0;j<a;j++){
			if(visit1[j]==false&&tim[j]<minn){
				minn=tim[j];
				u=j;
			}
		}
		if(u==-1) break;
		visit1[u]=true;
		for(int v=0;v<a;v++){
			if(visit1[v]==false&&ti[u][v]!=inf){
				if(tim[v]>tim[u]+ti[u][v]){
					tim[v]=tim[u]+ti[u][v];
					pre1[v].clear();
					pre1[v].push_back(u);
				}else if(tim[v]==tim[u]+ti[u][v]){
					pre1[v].push_back(u);
				} 
			}
			
		} 
	}
	dfs1(end,start);
	dfs2(end,start);
	if(path1==path2){
		printf("Distance = %d; Time = %d: ",dis[end],tim[end]);
		printf("%d",path1[path1.size()-1]);
		for(int i=path1.size()-2;i>=0;i--)
			printf(" -> %d",path1[i]);
	}else{
        printf("Distance = %d: ",dis[end]);
        printf("%d",path1[path1.size()-1]);
		for(int i=path1.size()-2;i>=0;i--)
		printf(" -> %d",path1[i]);
		printf("\n");
		printf("Time = %d: ",tim[end]);
        printf("%d",path2[path2.size()-1]);
		for(int i=path2.size()-2;i>=0;i--)
		printf(" -> %d",path2[i]);	
	}
}
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值