Pagini recente » Cod sursa (job #2897064) | Cod sursa (job #3040761) | Cod sursa (job #1425440) | Cod sursa (job #2630543) | Cod sursa (job #1626839)
#define FORN(i,n) for(int i=0;i<n;++i)
#define FOR(i,n) for(int i=1;i<=n;++i)
#include<fstream>
#include<iostream>
#include<set>
#include<map>
using namespace std;
ifstream f("dijkstra.in");
ofstream g("dijkstra.out");
int n,m;
struct point
{
set<int> legaturi;
map<int,int> costuri;
int cost;
};
point points[50000];
void rec(int pos)
{
for (std::map<int,int>::iterator it=points[pos].costuri.begin(); it!=points[pos].costuri.end(); ++it)
{
if(points[it->first].cost==0)
{
points[it->first].cost=points[pos].cost+it->second;
rec(it->first);
}
else if(points[pos].cost+it->second<points[it->first].cost)
{
points[it->first].cost=points[pos].cost+it->second;
}
}
}
int main()
{
f>>n>>n;
int aux1,aux2,aux3;
FORN(i,n)
{
f>>aux1>>aux2>>aux3;
points[aux1].costuri[aux2]=aux3;
}
rec(1);
FOR(i,n)
{
//cout<<i;
g<<points[i].cost<<" ";
}
f.close();
g.close();
return 0;
}