-
Notifications
You must be signed in to change notification settings - Fork 2
/
00341.cpp
55 lines (49 loc) · 1.28 KB
/
00341.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
using namespace std;
const int MAX = 0x0fffffff;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main()
{
vvi adjMat(10, vi(10) ), pathMat(10, vi(10) );
int nodes, src, dest, roads, road, delay, tmp, case_num = 1;;
while(cin >> nodes && nodes != 0)
{
fill(adjMat.begin(), adjMat.end(), vi(10, MAX) );
for(int i = 0; i < nodes; i++)
for(cin >> roads; roads--;)
{
cin >> road >> delay;
adjMat[i][--road] = delay;
pathMat[i][road] = i;
}
for(int k = 0; k < nodes; k++)
for(int i = 0; i < nodes; i++)
for(int j = 0; j < nodes; j++)
if( (adjMat[i][k] != MAX) && (adjMat[k][j] != MAX) && (adjMat[i][j] > adjMat[i][k] + adjMat[k][j]) )
{
adjMat[i][j] = adjMat[i][k] + adjMat[k][j];
pathMat[i][j] = pathMat[k][j];
}
cin >> src >> dest;
src--; dest--;
tmp = dest;
stack<int> intermediate;
intermediate.push(tmp+1);
do
{
tmp = pathMat[src][tmp];
intermediate.push(tmp+1);
}while(tmp != src);
cout << "Case " << case_num++ << ": Path =";
while(intermediate.size())
{
cout << ' ' << intermediate.top(); intermediate.pop();
}
cout << "; " << adjMat[src][dest] << " second delay" << endl;
}
return 0;
}