Submission #307548

# Submission time Handle Problem Language Result Execution time Memory
307548 2020-09-28T15:11:23 Z HynDuf Ceste (COCI17_ceste) C++11
160 / 160
510 ms 12908 KB
#include <bits/stdc++.h>

#define task "C"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vl;
const int N = 2002;
int n, m, mnCost[N];
ll ans[N];
viii g[N];
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n >> m;
    rep(i, 1, m)
    {
        int u, v, t, c;
        cin >> u >> v >> t >> c;
        g[u].pb({v, {t, c}});
        g[v].pb({u, {t, c}});
    }
    fill(ans, ans + 1 + n, 1e18);
    fill(mnCost, mnCost + 1 + n, 1e9);
    priority_queue<iii, viii, greater<iii> > pq;
    pq.push({0, {0, 1}});
    ans[1] = 0;
    while (!pq.empty())
    {
        int u = pq.top().S.S, t = pq.top().F, c = pq.top().S.F;
        pq.pop();
        if (c >= mnCost[u]) continue;
        mnCost[u] = c;
        ans[u] = min(ans[u], t * 1LL * c);
        for (iii E : g[u])
        {
            pq.push({t + E.S.F, {c + E.S.S, E.F}});
        }
    }
    rep(i, 2, n) cout << (ans[i] == 1e18 ? -1 : ans[i]) << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 1276 KB Output is correct
2 Correct 54 ms 1404 KB Output is correct
3 Correct 67 ms 1404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 191 ms 2156 KB Output is correct
2 Correct 510 ms 12908 KB Output is correct
3 Correct 7 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 832 KB Output is correct
2 Correct 301 ms 3772 KB Output is correct
3 Correct 13 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 260 ms 1080 KB Output is correct
2 Correct 238 ms 2280 KB Output is correct
3 Correct 212 ms 2160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 218 ms 2160 KB Output is correct
2 Correct 203 ms 2160 KB Output is correct
3 Correct 284 ms 2160 KB Output is correct