Submission #202481

# Submission time Handle Problem Language Result Execution time Memory
202481 2020-02-16T09:43:06 Z Kastanda Olympic Bus (JOI20_ho_t4) C++11
100 / 100
367 ms 1912 KB
// In The Name Of The Queen
#include<bits/stdc++.h>
using namespace std;
const int N = 209, M = 50004;
int n, m, U[M], V[M], C[M], DR[M], P[N];
bool MR[N], Mark[M];
long long F[N], D[N][N];
vector < int > Adj[N];
inline long long SSSP(int st, int fn, int j)
{
    memset(F, 63, sizeof(F));
    memset(MR, 0, sizeof(MR));
    F[st] = 0;
    for (int __ = 1; __ <= n; __ ++)
    {
        int v = -1;
        for (int i = 1; i <= n; i ++)
            if (!MR[i] && (v == -1 || F[v] > F[i]))
                v = i;
        MR[v] = 1;
        for (int i : Adj[v])
            if (i != j && F[V[i]] > F[v] + C[i])
                F[V[i]] = F[v] + C[i];
        if (v == V[j])
            if (F[U[j]] > F[v] + C[j])
                F[U[j]] = F[v] + C[j];
    }
    return (F[fn]);
}
inline long long Solve(int st, int fn)
{
    memset(P, 0, sizeof(P));
    memset(F, 63, sizeof(F));
    memset(MR, 0, sizeof(MR));
    memset(Mark, 0, sizeof(Mark));
    F[st] = 0;
    for (int __ = 1; __ <= n; __ ++)
    {
        int v = -1;
        for (int i = 1; i <= n; i ++)
            if (!MR[i] && (v == -1 || F[v] > F[i]))
                v = i;
        MR[v] = 1;
        for (int i : Adj[v])
            if (F[V[i]] > F[v] + C[i])
                F[V[i]] = F[v] + C[i],
                P[V[i]] = i;
    }
    long long Mn = LLONG_MAX;
    if (!P[fn])
        return (Mn);
    int v = fn;
    while (v != st)
        Mark[P[v]] = 1, v = U[P[v]];
    for (int i = 1; i <= m; i ++)
        if (!Mark[i])
            Mn = min(Mn, D[fn][V[i]] + C[i] + D[U[i]][st] + DR[i] + F[fn]);
    for (int j = 1; j <= m; j ++)
        if (Mark[j])
            Mn = min(Mn, SSSP(st, fn, j) + SSSP(fn, st, j) + DR[j]);
    return (Mn);
}
int main()
{
    scanf("%d%d", &n, &m);
    memset(D, 63, sizeof(D));
    for (int i = 1; i <= m; i ++)
    {
        scanf("%d%d%d%d", &U[i], &V[i], &C[i], &DR[i]);
        D[U[i]][V[i]] = min(D[U[i]][V[i]], 1LL * C[i]);
        Adj[U[i]].push_back(i);
    }
    for (int i = 1; i <= n; i ++)
        D[i][i] = 0;
    for (int k = 1; k <= n; k ++)
        for (int i = 1; i <= n; i ++)
            for (int j = 1; j <= n; j ++)
                D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
    long long Mn = D[1][n] + D[n][1];
    for (int i = 1; i <= m; i ++)
        if (D[1][V[i]] + C[i] + D[U[i]][n] < D[1][n] && D[n][V[i]] + C[i] + D[U[i]][1] < D[n][1])
            Mn = min(Mn, D[1][V[i]] + C[i] + D[U[i]][n] + D[n][V[i]] + C[i] + D[U[i]][1] + DR[i]);
    Mn = min(Mn, Solve(1, n));
    Mn = min(Mn, Solve(n, 1));
    if (Mn > (long long)(1e10) * n)
        Mn = -1;
    return !printf("%lld\n", Mn);
}

Compilation message

ho_t4.cpp: In function 'int main()':
ho_t4.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
ho_t4.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d%d", &U[i], &V[i], &C[i], &DR[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 23 ms 888 KB Output is correct
2 Correct 16 ms 764 KB Output is correct
3 Correct 21 ms 760 KB Output is correct
4 Correct 19 ms 764 KB Output is correct
5 Correct 6 ms 760 KB Output is correct
6 Correct 16 ms 764 KB Output is correct
7 Correct 5 ms 760 KB Output is correct
8 Correct 6 ms 760 KB Output is correct
9 Correct 5 ms 760 KB Output is correct
10 Correct 118 ms 764 KB Output is correct
11 Correct 116 ms 760 KB Output is correct
12 Correct 118 ms 760 KB Output is correct
13 Correct 16 ms 760 KB Output is correct
14 Correct 18 ms 760 KB Output is correct
15 Correct 18 ms 764 KB Output is correct
16 Correct 21 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 1784 KB Output is correct
2 Correct 44 ms 1656 KB Output is correct
3 Correct 45 ms 1784 KB Output is correct
4 Correct 18 ms 760 KB Output is correct
5 Correct 19 ms 760 KB Output is correct
6 Correct 15 ms 760 KB Output is correct
7 Correct 16 ms 760 KB Output is correct
8 Correct 5 ms 760 KB Output is correct
9 Correct 46 ms 1788 KB Output is correct
10 Correct 42 ms 1784 KB Output is correct
11 Correct 46 ms 1912 KB Output is correct
12 Correct 46 ms 1784 KB Output is correct
13 Correct 49 ms 1784 KB Output is correct
14 Correct 50 ms 1784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 760 KB Output is correct
2 Correct 15 ms 760 KB Output is correct
3 Correct 37 ms 1528 KB Output is correct
4 Correct 14 ms 760 KB Output is correct
5 Correct 39 ms 1784 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 5 ms 760 KB Output is correct
8 Correct 39 ms 1784 KB Output is correct
9 Correct 41 ms 1784 KB Output is correct
10 Correct 40 ms 1784 KB Output is correct
11 Correct 43 ms 1760 KB Output is correct
12 Correct 40 ms 1784 KB Output is correct
13 Correct 5 ms 760 KB Output is correct
14 Correct 5 ms 760 KB Output is correct
15 Correct 5 ms 760 KB Output is correct
16 Correct 5 ms 760 KB Output is correct
17 Correct 5 ms 760 KB Output is correct
18 Correct 5 ms 760 KB Output is correct
19 Correct 41 ms 1784 KB Output is correct
20 Correct 44 ms 1784 KB Output is correct
21 Correct 44 ms 1784 KB Output is correct
22 Correct 42 ms 1784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 888 KB Output is correct
2 Correct 16 ms 764 KB Output is correct
3 Correct 21 ms 760 KB Output is correct
4 Correct 19 ms 764 KB Output is correct
5 Correct 6 ms 760 KB Output is correct
6 Correct 16 ms 764 KB Output is correct
7 Correct 5 ms 760 KB Output is correct
8 Correct 6 ms 760 KB Output is correct
9 Correct 5 ms 760 KB Output is correct
10 Correct 118 ms 764 KB Output is correct
11 Correct 116 ms 760 KB Output is correct
12 Correct 118 ms 760 KB Output is correct
13 Correct 16 ms 760 KB Output is correct
14 Correct 18 ms 760 KB Output is correct
15 Correct 18 ms 764 KB Output is correct
16 Correct 21 ms 760 KB Output is correct
17 Correct 45 ms 1784 KB Output is correct
18 Correct 44 ms 1656 KB Output is correct
19 Correct 45 ms 1784 KB Output is correct
20 Correct 18 ms 760 KB Output is correct
21 Correct 19 ms 760 KB Output is correct
22 Correct 15 ms 760 KB Output is correct
23 Correct 16 ms 760 KB Output is correct
24 Correct 5 ms 760 KB Output is correct
25 Correct 46 ms 1788 KB Output is correct
26 Correct 42 ms 1784 KB Output is correct
27 Correct 46 ms 1912 KB Output is correct
28 Correct 46 ms 1784 KB Output is correct
29 Correct 49 ms 1784 KB Output is correct
30 Correct 50 ms 1784 KB Output is correct
31 Correct 20 ms 760 KB Output is correct
32 Correct 15 ms 760 KB Output is correct
33 Correct 37 ms 1528 KB Output is correct
34 Correct 14 ms 760 KB Output is correct
35 Correct 39 ms 1784 KB Output is correct
36 Correct 5 ms 760 KB Output is correct
37 Correct 5 ms 760 KB Output is correct
38 Correct 39 ms 1784 KB Output is correct
39 Correct 41 ms 1784 KB Output is correct
40 Correct 40 ms 1784 KB Output is correct
41 Correct 43 ms 1760 KB Output is correct
42 Correct 40 ms 1784 KB Output is correct
43 Correct 5 ms 760 KB Output is correct
44 Correct 5 ms 760 KB Output is correct
45 Correct 5 ms 760 KB Output is correct
46 Correct 5 ms 760 KB Output is correct
47 Correct 5 ms 760 KB Output is correct
48 Correct 5 ms 760 KB Output is correct
49 Correct 41 ms 1784 KB Output is correct
50 Correct 44 ms 1784 KB Output is correct
51 Correct 44 ms 1784 KB Output is correct
52 Correct 42 ms 1784 KB Output is correct
53 Correct 49 ms 1784 KB Output is correct
54 Correct 49 ms 1872 KB Output is correct
55 Correct 51 ms 1784 KB Output is correct
56 Correct 18 ms 760 KB Output is correct
57 Correct 17 ms 760 KB Output is correct
58 Correct 227 ms 1656 KB Output is correct
59 Correct 204 ms 1532 KB Output is correct
60 Correct 204 ms 1528 KB Output is correct
61 Correct 181 ms 1784 KB Output is correct
62 Correct 206 ms 1528 KB Output is correct
63 Correct 215 ms 1656 KB Output is correct
64 Correct 367 ms 1656 KB Output is correct
65 Correct 332 ms 1656 KB Output is correct
66 Correct 321 ms 1656 KB Output is correct
67 Correct 24 ms 1648 KB Output is correct
68 Correct 41 ms 1784 KB Output is correct
69 Correct 44 ms 1784 KB Output is correct
70 Correct 48 ms 1784 KB Output is correct
71 Correct 48 ms 1912 KB Output is correct
72 Correct 46 ms 1784 KB Output is correct
73 Correct 46 ms 1784 KB Output is correct
74 Correct 46 ms 1784 KB Output is correct