Pagini recente » Borderou de evaluare (job #963428) | Cod sursa (job #893101) | Borderou de evaluare (job #1837307) | Borderou de evaluare (job #896688) | Cod sursa (job #2358062)
#include <fstream>
#include <vector>
#include <queue>
#define dim 2001
#define pb push_back
using namespace std;
ifstream in("ubuntzei.in");
ofstream out("ubuntzei.out");
typedef pair<unsigned, unsigned> p;
vector<p> v[dim];
queue<unsigned> q;
unsigned long long cost[dim];
unsigned N, M, K;
void bfs(unsigned nod)
{
q.push(nod);
while(!q.empty())
{
unsigned el = q.front();
q.pop();
for(unsigned i = 0; i < v[el].size(); ++i)
if(cost[v[el][i].first] > cost[el] + v[el][i].second)
{
cost[v[el][i].first] = cost[el] + v[el][i].second;
q.push(v[el][i].first);
}
}
}
int main()
{
in >> N >> M >> K;
for(unsigned i = 1; i <= M; ++i)
{
unsigned x, y, z;
in >> x >> y >> z;
v[x].pb({y, z});
}
cost[1] = 0;
#define inf 0x3f3f3f3f
for(unsigned i = 2; i <= N;)
cost[i++] = inf;
bfs(1);
out << cost[N];
return 0;
}