Pagini recente » Cod sursa (job #2914086) | Cod sursa (job #666768) | Istoria paginii runda/shumenichb2013/clasament | Cod sursa (job #493844) | Cod sursa (job #1626845)
#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(int i=2;i<n;++i)
{
//cout<<i;
g<<points[i].cost<<" ";
}
f.close();
g.close();
return 0;
}