Submission #935702

# Submission time Handle Problem Language Result Execution time Memory
935702 2024-02-29T11:58:01 Z weakweakweak Olympic Bus (JOI20_ho_t4) C++14
100 / 100
413 ms 6532 KB
//抄解因為我笨,根本就不會最短路徑樹
//煩躁實作
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int,int>
#define fs first
#define sc second
const int inf  = 1e18, binf = inf + 11e9;
pii es[50100];
int n, m, C[50100], D[50100], ontree[50100] = {0};
vector <int> ans1n, ansn1, tree1n, treen1, e[210][210];
vector <int> ansxn[210], ansx1[210];
bool notused[50100] = {0};

pair< vector<int>, vector<int> > Dijkstra(int st, int ed);

int solve (int ei) {
    if (ontree[ei]) {
        notused[ei] = 1;
        e[es[ei].sc][es[ei].fs] . push_back(m + 1);
        C[m + 1] = C[ei], D[m + 1] = D[ei];
        int res = Dijkstra(1, n).fs[n];
        res += Dijkstra(n, 1).fs[1] + D[ei];
        notused[ei] = 0;
        e[es[ei].sc][es[ei].fs] . pop_back();
        return res;
    }
    else { 
        int res = ans1n[n] + ansn1[es[ei].sc] + ansx1[es[ei].fs][1] + C[ei] + D[ei]; 
        res = min(ans1n[es[ei].sc] + ansxn[es[ei].fs][n] + ansn1[1] + C[ei] + D[ei], res);
        res = min(ans1n[es[ei].sc] + ansxn[es[ei].fs][n] + ansn1[es[ei].sc] + ansx1[es[ei].fs][1] + C[ei] * 2 + D[ei], res);
        return res;
    }
}


pair< vector<int>, vector<int> > Dijkstra(int st, int ed) {
    vector <int> ans(n + 2, binf), vis(n + 2, 0), tree, from(n + 2, 0);
    ans[st] = 0;
    for (int t = 0; t <= n; t++) {
        int ii = 1;
        for (int i = 1; i <= n; i++) if (!vis[i]) ii = i;
        for (int i = 1; i <= n; i++) if (!vis[i] and ans[i] < ans[ii]) ii = i;
        if (vis[ii] or ans[ii] > inf) break;
        vis[ii] = 1;
        for (int j = 1; j <= n; j++) {
            if (vis[j] or !e[ii][j].size()) continue;
            for (int ei : e[ii][j] ) {
                if (notused[ei]) continue;
                if (ans[ii] + C[ei] < ans[j]) {
                    ans[j] = ans[ii] + C[ei];
                    from[j] = ei;
                }
            }
        }
    }
    for (int i = 1; i <= n; i++) if(i != st) tree.push_back(from[i]);
return {ans, tree};}


signed main () {
    ios_base :: sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> es[i].fs >> es[i].sc >> C[i] >> D[i];
        e[es[i].fs][es[i].sc].push_back(i);
    }

    auto rEs = Dijkstra (1, n);
    ans1n = rEs.fs, tree1n = rEs.sc;
    rEs = Dijkstra (n, 1);
    ansn1 = rEs.fs, treen1 = rEs.sc;
    for (int x : tree1n) ontree[x] = 1;
    for (int x : treen1) ontree[x] = 1;
    for (int i = 1; i <= n; i++) ansxn[i] = Dijkstra (i, n).fs, ansx1[i] = Dijkstra (i, 1).fs;

    int finans = ans1n[n] + ansn1[1];
    for (int i = 0; i < m; i++) finans = min(finans, solve(i));

    if (finans >= inf) finans = -1;
    cout << finans << '\n';
return 0;}
# Verdict Execution time Memory Grader output
1 Correct 109 ms 3152 KB Output is correct
2 Correct 11 ms 3164 KB Output is correct
3 Correct 177 ms 3172 KB Output is correct
4 Correct 181 ms 3360 KB Output is correct
5 Correct 2 ms 2648 KB Output is correct
6 Correct 10 ms 3160 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 154 ms 3216 KB Output is correct
11 Correct 185 ms 3152 KB Output is correct
12 Correct 171 ms 3360 KB Output is correct
13 Correct 71 ms 3360 KB Output is correct
14 Correct 119 ms 3352 KB Output is correct
15 Correct 135 ms 3292 KB Output is correct
16 Correct 111 ms 3152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 383 ms 5844 KB Output is correct
2 Correct 387 ms 5824 KB Output is correct
3 Correct 382 ms 5968 KB Output is correct
4 Correct 169 ms 3152 KB Output is correct
5 Correct 127 ms 3156 KB Output is correct
6 Correct 27 ms 3164 KB Output is correct
7 Correct 4 ms 3332 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 163 ms 6480 KB Output is correct
10 Correct 154 ms 5776 KB Output is correct
11 Correct 246 ms 5888 KB Output is correct
12 Correct 247 ms 6016 KB Output is correct
13 Correct 234 ms 5952 KB Output is correct
14 Correct 219 ms 5968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 3352 KB Output is correct
2 Correct 20 ms 3160 KB Output is correct
3 Correct 291 ms 5452 KB Output is correct
4 Correct 16 ms 3152 KB Output is correct
5 Correct 302 ms 6288 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 145 ms 5916 KB Output is correct
9 Correct 168 ms 6244 KB Output is correct
10 Correct 277 ms 5812 KB Output is correct
11 Correct 216 ms 5816 KB Output is correct
12 Correct 256 ms 5924 KB Output is correct
13 Correct 1 ms 2648 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 226 ms 6156 KB Output is correct
20 Correct 216 ms 5716 KB Output is correct
21 Correct 228 ms 5936 KB Output is correct
22 Correct 235 ms 6484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 3152 KB Output is correct
2 Correct 11 ms 3164 KB Output is correct
3 Correct 177 ms 3172 KB Output is correct
4 Correct 181 ms 3360 KB Output is correct
5 Correct 2 ms 2648 KB Output is correct
6 Correct 10 ms 3160 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 154 ms 3216 KB Output is correct
11 Correct 185 ms 3152 KB Output is correct
12 Correct 171 ms 3360 KB Output is correct
13 Correct 71 ms 3360 KB Output is correct
14 Correct 119 ms 3352 KB Output is correct
15 Correct 135 ms 3292 KB Output is correct
16 Correct 111 ms 3152 KB Output is correct
17 Correct 383 ms 5844 KB Output is correct
18 Correct 387 ms 5824 KB Output is correct
19 Correct 382 ms 5968 KB Output is correct
20 Correct 169 ms 3152 KB Output is correct
21 Correct 127 ms 3156 KB Output is correct
22 Correct 27 ms 3164 KB Output is correct
23 Correct 4 ms 3332 KB Output is correct
24 Correct 1 ms 2648 KB Output is correct
25 Correct 163 ms 6480 KB Output is correct
26 Correct 154 ms 5776 KB Output is correct
27 Correct 246 ms 5888 KB Output is correct
28 Correct 247 ms 6016 KB Output is correct
29 Correct 234 ms 5952 KB Output is correct
30 Correct 219 ms 5968 KB Output is correct
31 Correct 104 ms 3352 KB Output is correct
32 Correct 20 ms 3160 KB Output is correct
33 Correct 291 ms 5452 KB Output is correct
34 Correct 16 ms 3152 KB Output is correct
35 Correct 302 ms 6288 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2648 KB Output is correct
38 Correct 145 ms 5916 KB Output is correct
39 Correct 168 ms 6244 KB Output is correct
40 Correct 277 ms 5812 KB Output is correct
41 Correct 216 ms 5816 KB Output is correct
42 Correct 256 ms 5924 KB Output is correct
43 Correct 1 ms 2648 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2652 KB Output is correct
49 Correct 226 ms 6156 KB Output is correct
50 Correct 216 ms 5716 KB Output is correct
51 Correct 228 ms 5936 KB Output is correct
52 Correct 235 ms 6484 KB Output is correct
53 Correct 379 ms 6152 KB Output is correct
54 Correct 410 ms 6328 KB Output is correct
55 Correct 402 ms 6108 KB Output is correct
56 Correct 190 ms 3416 KB Output is correct
57 Correct 166 ms 3304 KB Output is correct
58 Correct 314 ms 5420 KB Output is correct
59 Correct 343 ms 5720 KB Output is correct
60 Correct 412 ms 5600 KB Output is correct
61 Correct 323 ms 5816 KB Output is correct
62 Correct 337 ms 5536 KB Output is correct
63 Correct 413 ms 6060 KB Output is correct
64 Correct 360 ms 5344 KB Output is correct
65 Correct 345 ms 5480 KB Output is correct
66 Correct 402 ms 5496 KB Output is correct
67 Correct 10 ms 4576 KB Output is correct
68 Correct 173 ms 6288 KB Output is correct
69 Correct 172 ms 6224 KB Output is correct
70 Correct 268 ms 6532 KB Output is correct
71 Correct 259 ms 5972 KB Output is correct
72 Correct 260 ms 6000 KB Output is correct
73 Correct 278 ms 5972 KB Output is correct
74 Correct 253 ms 5916 KB Output is correct