-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11779.cpp
More file actions
59 lines (58 loc) · 1.15 KB
/
11779.cpp
File metadata and controls
59 lines (58 loc) · 1.15 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
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define INF 987654321
int dist[1001];
int from[1001];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N,M,x,y,c;
cin>>N>>M;
vector<pair<int,int>>v[1001];
for(int i=0;i<M;i++)
{
cin>>x>>y>>c;
v[x].push_back({y,c});
}
int start,end;
cin>>start>>end;
for(int i=1;i<=N;i++)
dist[i]=INF;
dist[start]=0;
from[start]=-1;
queue<int> q;
q.push(start);
while(!q.empty())
{
int cur=q.front();
q.pop();
for(int i=0;i<v[cur].size();i++)
{
int dest=v[cur][i].first;
int cost=v[cur][i].second;
if(dist[dest]>dist[cur]+cost)
{
dist[dest]=dist[cur]+cost;
from[dest]=cur;
q.push(dest);
}
}
}
cout<<dist[end]<<'\n';
stack<int> s;
while(end!=-1)
{
s.push(end);
end=from[end];
}
cout<<s.size()<<'\n';
while(!s.empty())
{
cout<<s.top()<<' ';
s.pop();
}
}