Submission #641789

#TimeUsernameProblemLanguageResultExecution timeMemory
641789danikoynovOlympic Bus (JOI20_ho_t4)C++14
11 / 100
73 ms1960 KiB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 210, maxm = 50010;
const ll inf = 1e17;
struct edge
{
    int v, u;
    ll c, d;
} e[maxm];

bool cmp_d(edge e1, edge e2)
{
    return e1.d < e2.d;
}

int n, m, used[maxn], cap[maxn][maxn];
ll dp[maxn][maxn], path[maxn][maxn];
ll dist[maxn];

void dijkstra(int v)
{
    for (int i = 1; i <= n; i ++)
        dist[i] = inf, used[i] = 0;

    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= n; j ++)
    {
        if (i != j)
            path[i][j] = inf;
    }

    for (int j = 1; j <= m; j ++)
    {
        path[e[j].v][e[j].u] = min(path[e[j].v][e[j].u], e[j].c);
    }

    int cur = v;
    dist[cur] = 0;
    used[cur] = 1;
    while(true)
    {
        int mx = -1;
        for (int i = 1; i <= n; i ++)
        {
            if (!used[i] && (mx == -1 || dist[i] < dist[mx]))
                mx = i;
        }

        if (mx == -1)
            break;

        cur = mx;
        used[cur] = 1;
        for (int i = 1; i <= n; i ++)
        {
            if (!used[i] && dist[cur] + path[i][cur] < dist[i])
            {
                dist[i] = dist[cur] + path[i][cur];
            }
        }
    }
}
void solve()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= n; j ++)
    {
        if (i != j)
            dp[i][j] = inf;
    }


    bool czero = true;
    for (int i = 1; i <= m; i ++)
    {
        cin >> e[i].v >> e[i].u >> e[i].c >> e[i].d;
        dp[e[i].v][e[i].u] = min(dp[e[i].v][e[i].u], (ll)e[i].c);
        if (e[i].c != 0)
            czero = false;
    }

        for (int k = 1; k <= n; k ++)
            for (int i = 1; i <= n; i ++)
            for (int j = 1; j <= n; j ++)
        {
            if (dp[i][k] + dp[k][j] < dp[i][j])
                dp[i][j] = dp[i][k] + dp[k][j];
        }

        ll ans = dp[1][n] + dp[n][1];
        for (int i = 1; i <= m; i ++)
        {
            int v = e[i].v, u = e[i].u;

            ll cur = min(dp[1][u] + dp[v][n] + e[i].c, dp[1][n]) + min(dp[n][u] + dp[v][1] + e[i].c, dp[n][1]) + e[i].d;
             ///if (e[i].d < 74779 && e[i].c < 74779 && dp[v][1] < 74779)
            ///cout << cur << " " << e[i].d << " " << e[i].c << " " << dp[n][u] << " " << dp[v][1] << endl;
            if (cur < ans)
                ans = cur;
        }

        if (ans < inf)
        cout << ans << endl;
        else
            cout << -1 << endl;


}

int main()
{
    ///freopen("test.txt", "r", stdin);
    solve();
    return 0;
}

/**
4 4
2 1 0 4
3 1 0 1
3 4 0 2
1 4 0 1
*/

Compilation message (stderr)

ho_t4.cpp: In function 'void solve()':
ho_t4.cpp:93:10: warning: variable 'czero' set but not used [-Wunused-but-set-variable]
   93 |     bool czero = true;
      |          ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...