This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Make the best become better
// No room for laziness
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 2000 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e14;
int n, m;
struct TAdj
{
int v, w, c;
};
vector<TAdj> adj[maxN];
int d[maxN][2005];
struct TPQRect
{
int vertex, time, dlab;
bool operator < (const TPQRect& other) const
{
return other.dlab < dlab;
}
bool Valid() const
{
return d[vertex][time] == dlab;
}
};
void ReadInput()
{
cin >> n >> m;
for(int i=1; i<=m; i++)
{
int u, v, w, c;
cin >> u >> v >> w >> c;
adj[u].pb({v, w, c});
adj[v].pb({u, w, c});
}
}
void Dijkstra()
{
memset(d, 3, sizeof d);
d[1][0] = 0;
priority_queue<TPQRect> pq;
pq.push({1, 0, 0});
while(!pq.empty())
{
TPQRect r = pq.top();
pq.pop();
if(!r.Valid()) continue;
int u = r.vertex, t = r.time;
for(TAdj a : adj[u])
{
if(t + a.w > 2000) continue;
if(d[a.v][t + a.w] > d[u][t] + a.c)
{
d[a.v][t + a.w] = d[u][t] + a.c;
pq.push({a.v, t + a.w, d[a.v][t + a.w]});
}
}
}
}
void Solve()
{
Dijkstra();
for(int i=2; i<=n; i++)
{
int res = oo;
for(int j=1; j<=2000; j++)
if(d[i][j] < oo) res = min(res, j * d[i][j]);
cout << (res < oo ? res : -1) << '\n';
}
}
int32_t main()
{
//freopen("sol.inp", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ReadInput();
Solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |