-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11780.cpp
More file actions
74 lines (73 loc) · 1.5 KB
/
11780.cpp
File metadata and controls
74 lines (73 loc) · 1.5 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
#define INF 987654321
int dist[101][101];
int v[101][101];
int main()
{
memset(dist,INF,sizeof(dist));
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N,M,a,b,c;
cin>>N>>M;
for(int i=1;i<=N;i++)
{
for(int j=1;j<=N;j++)
dist[i][j]=(i==j?0:INF);
}
for(int i=0;i<M;i++)
{
cin>>a>>b>>c;
if(dist[a][b]>c)
{
dist[a][b]=c;
v[a][b]=b;
}
}
for(int k=1;k<=N;k++)
{
for(int i=1;i<=N;i++)
{
for(int j=1;j<=N;j++)
{
if(dist[i][j]>dist[i][k]+dist[k][j])
{
dist[i][j]=dist[i][k]+dist[k][j];
v[i][j]=v[i][k];
}
}
}
}
for(int i=1;i<=N;i++)
{
for(int j=1;j<=N;j++)
{
if(i==j||dist[i][j]==INF)
cout<<"0 ";
else
cout<<dist[i][j]<<" ";
}
cout<<'\n';
}
for(int i=1;i<=N;i++)
{
for(int j=1;j<=N;j++)
{
if(i==j||dist[i][j]==INF){
cout<<"0\n";
continue;
}
vector<int> p(1,i);
for(int k=i;k!=j;){
p.push_back(k=v[k][j]);
}
cout<<p.size();
for(int k : p) cout<<" "<<k;
cout<<"\n";
}
}
return 0;
}