Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <vector>
- #include <queue>
- #define inf 1000000000
- using namespace std;
- ifstream fin("input.txt");
- ofstream fout("output.txt");
- int main()
- {
- int N,M,da,to,a,b,p;
- da--;
- to--;
- fin>>N>>M;
- fin>>da>>to;
- vector<pair<int,int>> G[N];
- for(int i=0; i<M; i++)
- {
- fin>>a>>b>>p;
- a--;
- b--;
- G[a].push_back(make_pair(b,p));
- G[b].push_back(make_pair(a,p));
- }
- vector<int> dist(N,inf);
- queue<int> q;
- q.push(da);
- dist[da]=0;
- while(!q.empty())
- {
- int curr=q.front();
- q.pop();
- for(auto x:G[curr])
- {
- if(dist[curr]+x.second<dist[x.first])
- {
- q.push(x.first);
- dist[x.first]=dist[curr]+x.second;
- }
- }
- }
- fout<<dist[to];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement