Pagini recente » Monitorul de evaluare | Cod sursa (job #3360143) | Cod sursa (job #3360336) | Cod sursa (job #3360130) | Cod sursa (job #3360139)
#include <fstream>
#pragma GCC optimize("O3,unroll-loops")
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <iomanip>
#include <numeric>
#include <bitset>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#define int long long
//#define int short
using namespace std;
ifstream cin("dmin.in");
ofstream cout("dmin.out");
const int nmax = 1500;
const int inf = 2e9;
const int mod = 104659;
const double eps = 1e-9;
int n, m, cnt[nmax + 5];
double dis[nmax + 5];
vector<pair<int, int>> adj[nmax + 5];
struct cmp{
bool operator()(const pair<int, int>& a, const pair<int, int>& b)const{
return a.second > b.second;
}
};
void dijkstra(int stnode){
priority_queue<pair<int, double>, vector<pair<int, double>>, cmp> pq;
dis[stnode] = 0;
cnt[stnode] = 1;
pq.push({stnode, 0.0});
while (!pq.empty()){
int curnode = pq.top().first, curweight = pq.top().second;
pq.pop();
if (dis[curnode] < curweight){
continue;
}
for (auto& [node, weight] : adj[curnode]){
int newweight = weight + curweight;
if (dis[node] > newweight){
dis[node] = newweight;
cnt[node] = cnt[curnode];
pq.push({node, newweight});
}
else if (newweight - dis[node] <= eps){
cnt[node] += cnt[curnode];
cnt[node] %= mod;
}
}
}
}
signed main(){
cin>>n>>m;
while (m--){
int u, v;
double w;
cin>>u>>v>>w;
w = log2(w);
adj[u].push_back({v, w});
adj[v].push_back({u, w});
}
for (int i = 1; i <= n; i++){
dis[i] = inf;
}
dijkstra(1);
for (int i = 2; i <= n; i++){
cout<<cnt[i]<<" ";
}
}