Pagini recente » Cod sursa (job #3247283) | Cod sursa (job #2446716) | Cod sursa (job #1660696) | Cod sursa (job #2547719) | Cod sursa (job #2489187)
#include <fstream>
#include <vector>
#include <utility>
#define NMAX 100000
using namespace std;
ifstream f("file.in");
ofstream g("rf.out");
int n,m;
vector <pair <int,int>> v[NMAX];
vector <int> viz;
priority_queue <pair <int,pair <int,int>>> h;
int main()
{
f>>n>>m;
for(int i=0;i<n;++i)
viz.push_back(0);
while(m--)
{
int x,y,z;
f>>x>>y>>z;
v[x].push_back(make_pair(y,z));
}
for(auto x:v[0])
h.push(make_pair(x.second,make_pair(0,x.first)));
viz[0]=1;
while(!h.empty())
{
pair<int,pair<int,int>> e=h.top();
h.pop();
viz[e.second.second]=1;
for(auto x:v[e.second.second])
if(!viz[x.first])
h.push(make_pair(x.second,make_pair(e.second.second,x.first)));
}
return 0;
}