답안 #758906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
758906 2023-06-15T13:47:01 Z xyzxyz Olympic Bus (JOI20_ho_t4) C++14
37 / 100
1000 ms 10200 KB
#include<bits/stdc++.h>

#define int long long

using namespace std;

vector<int> kosten;

void dijkstra(vector<set<pair<int,int>>>& adj, vector<long long>& dist, int start, vector<pair<int,int>>&parent){
    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
    dist[start] = 0;
    pq.push({0,start});
    while(!pq.empty()){
        int wo = pq.top().second, preis = pq.top().first;
        pq.pop();
        if(dist[wo]== preis){
            for(auto[ziel, index]: adj[wo]){
                if(dist[ziel] > kosten[index]+preis){
                    dist[ziel] = kosten[index]+preis;
                    parent[ziel] = {wo, index};
                    pq.push({dist[ziel], ziel});
                }
            }
        }
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int v, e; cin >> v >> e;
    vector<set<pair<int,int>>> adj(v), adj2(v);
    vector<tuple<int,int,int,int>> edges(e);
    vector<int> umdrehkosten(e);
    kosten = vector<int>(e);
    for(int i=0; i<e; i++){
        int a, b; cin >> a >> b >> kosten[i] >> umdrehkosten[i];
        a--; b--;
        adj[a].insert({b, i});
        adj2[b].insert({a, i});//umgedrehter Graph
        edges[i] = make_tuple(a,b,kosten[i],umdrehkosten[i]);
    }
    vector<long long> von0(v, 1e17), vonn_r(v, 1e17), vonn(v, 1e17), von0_r(v, 1e17);
    vector<pair<int,int>> parent0(v, {-1, -1}), parent2(v, {-1, -1}), parentn(v, {-1, -1});
    dijkstra(adj, von0, 0, parent0);
    dijkstra(adj2, vonn_r, v-1, parent2);
    dijkstra(adj2, von0_r, 0, parent2);
    dijkstra(adj, vonn, v-1, parentn);
    int ort = v-1;
    vector<bool> used(e, false);
    while(parent0[ort].first!=-1){
        used[parent0[ort].second] = true;
        ort = parent0[ort].first;
    }
    ort = 0;
    while(parentn[ort].first!=-1){
        used[parentn[ort].second] = true;
        ort = parentn[ort].first;
    }
    int res = min((long long)1e17, (long long)von0[v-1]+vonn[0]);//keine Kante gedreht
    for(int i=0; i<e; i++){
        auto [start, ende, cost, r_cost] = edges[i];
        if(used[i]){
            adj[start].erase({ende, i});
            adj[ende].insert({start, i});
            vector<long long> dist(v, 1e17), dist2(v, 1e17);
            dijkstra(adj, dist, 0, parent0);
            dijkstra(adj, dist2, v-1, parent0);
            res = min(res, dist[v-1]+dist2[0]+r_cost);
            adj[start].insert({ende, i});
            adj[ende].erase({start, i});
        }else{
            int a = min(vonn[0], vonn[ende] + cost + von0_r[start]);
            int b = min(von0[v-1], von0[ende] + cost + vonn_r[start]);
            res = min(res, a + b + r_cost);
        }
    }
    if(res!=1e17) cout << res;
    else cout << -1;
    return 0;
}

Compilation message

ho_t4.cpp: In function 'void dijkstra(std::vector<std::set<std::pair<long long int, long long int> > >&, std::vector<long long int>&, long long int, std::vector<std::pair<long long int, long long int> >&)':
ho_t4.cpp:17:21: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   17 |             for(auto[ziel, index]: adj[wo]){
      |                     ^
ho_t4.cpp: In function 'int main()':
ho_t4.cpp:62:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   62 |         auto [start, ende, cost, r_cost] = edges[i];
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 456 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 380 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 17 ms 556 KB Output is correct
11 Correct 22 ms 460 KB Output is correct
12 Correct 22 ms 456 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 10016 KB Output is correct
2 Correct 49 ms 9880 KB Output is correct
3 Correct 48 ms 10060 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 2 ms 432 KB Output is correct
6 Correct 1 ms 456 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 34 ms 10096 KB Output is correct
10 Correct 33 ms 10048 KB Output is correct
11 Correct 48 ms 10052 KB Output is correct
12 Correct 44 ms 10104 KB Output is correct
13 Correct 45 ms 10112 KB Output is correct
14 Correct 53 ms 10200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 37 ms 7716 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 45 ms 9840 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 35 ms 9804 KB Output is correct
9 Correct 34 ms 9880 KB Output is correct
10 Correct 56 ms 9884 KB Output is correct
11 Correct 45 ms 9780 KB Output is correct
12 Correct 42 ms 9796 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 43 ms 9828 KB Output is correct
20 Correct 43 ms 9892 KB Output is correct
21 Correct 43 ms 9820 KB Output is correct
22 Correct 44 ms 9896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 456 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 380 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 17 ms 556 KB Output is correct
11 Correct 22 ms 460 KB Output is correct
12 Correct 22 ms 456 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 60 ms 10016 KB Output is correct
18 Correct 49 ms 9880 KB Output is correct
19 Correct 48 ms 10060 KB Output is correct
20 Correct 2 ms 716 KB Output is correct
21 Correct 2 ms 432 KB Output is correct
22 Correct 1 ms 456 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 34 ms 10096 KB Output is correct
26 Correct 33 ms 10048 KB Output is correct
27 Correct 48 ms 10052 KB Output is correct
28 Correct 44 ms 10104 KB Output is correct
29 Correct 45 ms 10112 KB Output is correct
30 Correct 53 ms 10200 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 37 ms 7716 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 45 ms 9840 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 35 ms 9804 KB Output is correct
39 Correct 34 ms 9880 KB Output is correct
40 Correct 56 ms 9884 KB Output is correct
41 Correct 45 ms 9780 KB Output is correct
42 Correct 42 ms 9796 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 43 ms 9828 KB Output is correct
50 Correct 43 ms 9892 KB Output is correct
51 Correct 43 ms 9820 KB Output is correct
52 Correct 44 ms 9896 KB Output is correct
53 Correct 64 ms 10056 KB Output is correct
54 Correct 71 ms 9932 KB Output is correct
55 Correct 65 ms 9956 KB Output is correct
56 Correct 2 ms 468 KB Output is correct
57 Correct 2 ms 468 KB Output is correct
58 Correct 393 ms 8104 KB Output is correct
59 Correct 476 ms 8100 KB Output is correct
60 Correct 671 ms 8100 KB Output is correct
61 Correct 438 ms 8100 KB Output is correct
62 Correct 460 ms 8104 KB Output is correct
63 Correct 662 ms 8092 KB Output is correct
64 Execution timed out 1004 ms 8848 KB Time limit exceeded
65 Halted 0 ms 0 KB -