Submission #224163

# Submission time Handle Problem Language Result Execution time Memory
224163 2020-04-17T08:59:54 Z cheeheng Olympic Bus (JOI20_ho_t4) C++14
0 / 100
99 ms 4448 KB
#include <bits/stdc++.h>
using namespace std;

typedef tuple<int, int, int> iii;
typedef pair<long long, long long> ii;

const long long INF = 1LL << 61;

set<iii> AdjList[205];
int cnt[205][205];

int U[50005];
int V[50005];
int C[50005];
int D[50005];

long long dist[205];

int N, M;

long long dijkstra(){
    for(int i = 1; i <= N; i ++){
        dist[i] = INF;
    }
    dist[1] = 0;
    priority_queue<ii, vector<ii>, greater<ii> > pq;
    while(!pq.empty()){
        long long d, u;
        ii temp = pq.top(); pq.pop();
        tie(d, u) = temp;

        if(d > dist[u]){continue;}

        for(iii v2: AdjList[u]){
            int v, w, x;
            tie(v, w, x) = v2;
            if(dist[v] > w + dist[u]){
                dist[v] = w + dist[u];
                pq.push(ii(dist[v], v));
            }
        }
    }
    return dist[N];
}

int main(){
    scanf("%d%d", &N, &M);

    memset(cnt, 0, sizeof(cnt));

    for(int i = 0; i < M; i ++){
        int u, v, c, d;
        scanf("%d%d%d%d", &u, &v, &c, &d);
        U[i] = u;
        V[i] = v;
        C[i] = c;
        D[i] = d;
        AdjList[u].insert(iii(v, c, d));
    }

    long long ans = dijkstra();
    for(int i = 0; i < M; i ++){
        AdjList[U[i]].erase(iii(V[i], C[i], D[i]));
        AdjList[V[i]].insert(iii(U[i], C[i], D[i]));
        ans = min(ans, D[i] + dijkstra());
        AdjList[V[i]].erase(iii(U[i], C[i], D[i]));
        AdjList[U[i]].insert(iii(V[i], C[i], D[i]));
    }

    if(ans == INF){
        ans = -1;
    }
    printf("%lld", ans);
    return 0;
}

Compilation message

ho_t4.cpp: In function 'int main()':
ho_t4.cpp:47: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:53:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d%d", &u, &v, &c, &d);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 99 ms 4448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -