Pagini recente » Cod sursa (job #3243805) | Cod sursa (job #2354815) | Cod sursa (job #504585) | Cod sursa (job #1812339) | Cod sursa (job #1801495)
#include <bits/stdc++.h>
#define NMAX 1005
#define KMAX 11
using namespace std;
ifstream fin ("retea.in");
ofstream fout ("retea.out");
double D[NMAX][KMAX];
vector < pair <int,int> > G[NMAX];
struct cmp{
bool operator()(const int &a, const int &b){
return D[a][0] > D[b][0];
}
};
priority_queue < int , vector < int > , cmp > heap;
void dijkstra(){
int nod;
heap.push(1);
while(!heap.empty()){
nod = heap.top();
heap.pop();
for(int i = 0; i < G[nod].size(); i++){
if(D[G[nod][i].first][0] > D[nod][0] + G[nod][i].second){
D[G[nod][i].first][0] = D[nod][0] + G[nod][i].second;
heap.push(G[nod][i].first);
}
}
}
}
int main()
{
ios :: sync_with_stdio(false);
fin.tie(NULL);
int n,m,k,x,y,c;
fin >> n >> m >> k;
for(int i = 1; i <= m; i++){
fin >> x >> y >> c;
G[x].push_back({y,c});
G[y].push_back({x,c});
}
for(int i = 2; i <= n; i++)
D[i][0] = 0;
dijkstra();
cout << "Hello world!" << endl;
return 0;
}