Mai intai trebuie sa te autentifici.
Cod sursa(job #977291)
Utilizator | Data | 25 iulie 2013 14:45:46 | |
---|---|---|---|
Problema | Drumuri minime | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 1.11 kb |
#include <fstream>
#include <queue>
using namespace std;
ifstream fin ("dmin.in");
ofstream fout ("dmin.out");
#define N 1505
#define xx first
#define yy second
#define MOD 104659
#define oo 0x3f3f3f3f
typedef pair <int, int> nod;
vector <nod> g[N];
int f[N], d[N], n, m, q[N];
priority_queue <nod, vector <nod>, greater <nod> > H;
int main() {
fin >> n >> m;
while (m--) {
int x, y, z;
fin >> x >> y >> z;
g[x].push_back (nod (y, z));
g[y].push_back (nod (x, z));
}
for (int i = 1; i <= n; ++i)
d[i] = oo;
fin.close();
H.push (nod (0, 1));
d[1] = 0;
q[1]++;
while (H.size()) {
nod x = H.top(); H.pop();
if (d[x.yy] < x.xx)
continue;
q[x.yy]--;
f[x.yy] = (f[x.yy] + 1) % MOD;
for (vector <nod> :: iterator it = g[x.yy].begin(); it != g[x.yy].end(); ++it)
if (d[(*it).xx] == oo || q[(*it).xx]) {
int NEW = d[x.yy] + (*it).second;
H.push(nod (NEW, (*it).xx));
if (NEW < d[(*it).xx]) {
d[(*it).xx] = NEW;
q[(*it).xx] = 1;
}
else
if (NEW == d[(*it).xx])
q[(*it).xx]++;
}
}
for (int i = 2; i <= n; ++i)
fout << f[i] << " ";
fout.close();
}