Pagini recente » Cod sursa (job #1894828) | Cod sursa (job #2237354) | Cod sursa (job #2401891) | Cod sursa (job #1010906) | Cod sursa (job #1041898)
#include <iostream>
#include <queue>
#include <fstream>
#define f first
#define s second
#define newn a[x.s][i]
using namespace std;
ifstream fin("camionas.in");
ofstream fout("camionas.out");
const int N = 50005;
const int oo = 0x3f3f3f3f;
int n, m, g, d[N];
typedef pair <int, int> nod;
priority_queue <nod, vector<nod>, less<nod> >h;
vector <bool> viz(N), cost[N];
vector <int> a[N];
void Dijkstra()
{
for(int i=1; i<=n; i++)
d[i] = oo;
d[1] = 0; h.push(nod(0, 1));
while(!h.empty())
{
nod x = h.top(); h.pop();
viz[x.s] = 1;
for(unsigned i=0; i<a[x.s].size(); i++)
if(!viz[newn] && d[newn] > d[newn] + cost[x.s][i])
{
d[newn] = d[x.s] + cost[x.s][i];
h.push(nod(d[newn], newn));
}
}
}
int main()
{
fin>>n>>m>>g;
while(m--)
{
int x, y, c;
fin>>x>>y>>c;
a[x].push_back(y);
a[y].push_back(x);
if(c < g)
{
cost[x].push_back(1);
cost[y].push_back(1);
}
else
{
cost[x].push_back(0);
cost[y].push_back(0);
}
}
Dijkstra();
fout<<d[n];
return 0;
}