답안 #239686

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
239686 2020-06-17T07:42:40 Z kartel Ceste (COCI17_ceste) C++14
96 / 160
381 ms 3064 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define N +100500
#define M ll(1e9 + 7)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e9)
#define el '\n'
#define pii pair <int, int>
#define err ld(1e-9)
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;

ll ans[N], A[N], B[N], x, y, u, v, i, j, n, m;
vector <pair <int, int> > g[N];
ld cs, sn;
pair <ld, pair <int, int> > dist[N];

set <pair <ld, int> > q;

int main()
{
    srand(time(0));
    ios_base::sync_with_stdio(0);
    iostream::sync_with_stdio(0);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

//    in("input.txt");
//    out("output.txt");

    cin >> n >> m;
    for (i = 1; i <= m; i++)
    {
        cin >> v >> u >> A[i] >> B[i];

        g[u].pb({v, i});
        g[v].pb({u, i});
    }

    for (i = 1; i <= n; i++) ans[i] = 1e18;

    sn = 1;
    cs = 0;

    while (1)
    {
        for (i = 1; i <= n; i++) dist[i] = {1e18, {1e9, 1e9}};

        q.insert({0.0, 1});

        dist[1] = {0.0, {0, 0}};

        while (sz(q))
        {
            int v = (*q.begin()).S;

            q.erase(q.begin());

            for (auto to : g[v])
            {
                int u = to.F;
                int i = to.S;

                ld new_dist = dist[v].F + sn * ld(A[i]) + cs * ld(B[i]);

                if (new_dist + err < dist[u].F)
                {
                    q.erase({dist[u].F, u});

                    dist[u] = {new_dist, {dist[v].S.F + A[i], dist[v].S.S + B[i]}};

                    q.insert({dist[u].F, u});
                }
            }
        }

        ld new_sin = 0;

        for (v = 1; v <= n; v++)
        {
            if (dist[v].F == 1e18) continue;

            if (v > 1)
                ans[v] = min(ans[v], ll(dist[v].S.F * dist[v].S.S));

            for (auto to : g[v])
            {
                int u = to.F;
                int i = to.S;

                ll s = (dist[v].S.F + A[i]) - dist[u].S.F;
                ll c = (dist[v].S.S + B[i]) - dist[u].S.S;

                if (s == c) continue;

                ld maybe = ld(c) / (ld(c) - ld(s));

                if (maybe + err < sn && maybe > new_sin)
                    new_sin = maybe;
            }
        }

        if (new_sin >= sn) break;

        sn = new_sin;
        cs = 1 - sn;
    }

    for (i = 2; i <= n; i++)
       if (ans[i] == 1e18)
         cout << "-1" << el;
    else cout << ans[i] << el;
}

/*
8 8
...).).*
*....)..
.)*(..).
(*)((...
.)).)(..
.)(.)..(
...).(.*
M.......
*/
//
//110000
//1100
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 2944 KB Output is correct
2 Correct 182 ms 2792 KB Output is correct
3 Correct 45 ms 2936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 2816 KB Output is correct
2 Correct 30 ms 2816 KB Output is correct
3 Correct 43 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 220 ms 3064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 381 ms 2944 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 172 ms 2936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 221 ms 2944 KB Output is correct
2 Incorrect 273 ms 2944 KB Output isn't correct
3 Halted 0 ms 0 KB -