QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#876947#2501. Olympic BusWansur#0 0ms0kbC++261.9kb2025-01-31 15:48:342025-01-31 15:48:34

Judging History

This is the latest submission verdict.

  • [2025-01-31 15:48:34]
  • Judged
  • Verdict: 0
  • Time: 0ms
  • Memory: 0kb
  • [2025-01-31 15:48:34]
  • Submitted

answer

#include <bits/stdc++.h>
#define ent '\n'
// #define int long long

// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")

typedef long long ll;
using namespace std;

const int maxn = 400 + 12;
const int inf = (int)2e9 + (int)1e8;

int cost[202][202];
int u[maxn], v[maxn], w[maxn], c[maxn];
int d1[maxn], dn[maxn];
bool used[maxn];
int n, m, k;

void work(int ver, int d[]) {
    for(int i = 1; i <= n; i++) {
        d[i] = inf;
        used[i] = false;
    }
    d[ver] = 0;
    for(int t = 0; t < n; t++) {
        int v = 0;
        for(int i = 1; i <= n; i++) {
            if((!v || d[i] < d[v]) && !used[i]) {
                v = i;
            }
        }
        if(!v || d[v] == inf) break;
        used[v] = true;
        for(int i = 1; i <= n; i++) {
            if(cost[v][i] < inf) {
                d[i] = min(d[i], d[v] + cost[v][i]);
            }
        }
    }
}

void solve() {
    cin >> n >> m;
    for(int i = 1; i <= m; i++) {
        cin >> u[i] >> v[i] >> w[i] >> c[i];
    }
    int ans = inf;
    for(int pos = 0; pos <= m; pos++) {
        swap(u[pos], v[pos]);
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                cost[i][j] = inf;
            }
            cost[i][i] = 0;
        }
        for(int i = 1; i <= m; i++) {
            cost[u[i]][v[i]] = min(cost[v[i]][u[i]], w[i]);
        }

        work(1, d1);
        work(n, dn);

        if(d1[n] < inf && dn[1] < inf) {
            ans = min(ans, d1[n] + dn[1] + c[pos]);
        }
        swap(u[pos], v[pos]);
    }
    if(ans >= inf) ans = -1;
    cout << ans << ent;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

200 1000
122 152 0 182437847
22 126 0 800796216
142 158 0 932784437
27 61 0 220600502
2 106 0 369508879
150 200 0 576962057
99 9 0 588062163
101 72 0 148003923
9 182 0 732139947
84 88 0 720592694
198 161 0 151363245
89 187 0 214138025
160 150 0 82621350
63 170 0 665493133
135 144 0 571301198
118 29 ...

output:


result:


Subtask #2:

score: 0
Runtime Error

Test #17:

score: 0
Runtime Error

input:

200 50000
92 72 987034 981351
92 72 987034 428035
95 16 263441 869630
95 16 263441 274419
18 67 742896 495941
18 67 742896 773584
89 7 456457 702434
89 7 456457 631522
52 193 188333 207969
52 193 188333 151198
32 144 801401 523873
32 144 801401 485433
114 30 945638 685397
114 30 945638 387101
177 94...

output:


result:


Subtask #3:

score: 0
Runtime Error

Test #31:

score: 0
Runtime Error

input:

200 1000
29 42 0 73206665
155 127 0 684640269
50 198 0 321195054
144 61 0 823740117
102 146 0 503128895
56 38 0 739648322
181 24 0 720383720
197 37 0 235418116
57 184 0 493283302
125 96 0 845930225
11 59 0 18751364
101 122 0 175819721
123 151 0 99670888
111 194 0 526645991
132 64 0 904239661
103 173...

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%