QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#876949#2501. Olympic BusWansur#0 208ms8040kbC++261.9kb2025-01-31 15:49:442025-01-31 15:49:44

Judging History

This is the latest submission verdict.

  • [2025-01-31 15:49:44]
  • Judged
  • Verdict: 0
  • Time: 208ms
  • Memory: 8040kb
  • [2025-01-31 15:49:44]
  • 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 = 1e5 + 12;
const int inf = (int)1e12 + (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();
    }
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 163ms
memory: 6124kb

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:

0

result:

ok single line: '0'

Test #2:

score: 5
Accepted
time: 4ms
memory: 7784kb

input:

200 250
87 77 0 413690178
44 146 0 580238372
96 86 0 471635629
76 37 0 460314897
36 26 0 797795878
186 196 0 340458462
137 148 0 8238512
63 102 0 83585569
128 92 0 355539314
111 136 0 941271932
120 25 0 670904911
68 143 0 789757256
50 24 0 57273302
166 33 0 961114401
151 122 0 88660198
162 71 0 2027...

output:

-1

result:

ok single line: '-1'

Test #3:

score: 5
Accepted
time: 208ms
memory: 5988kb

input:

200 1000
32 195 208991 761039285
174 149 435536 435440777
109 29 693056 976975992
47 44 590890 186457226
80 65 353546 61953096
163 79 124971 309842392
5 82 341956 789963665
124 175 650665 600626885
46 79 450500 56179506
78 99 803108 312872894
194 48 926872 609270327
47 31 865000 911848359
113 46 598...

output:

2437514

result:

ok single line: '2437514'

Test #4:

score: 0
Wrong Answer
time: 203ms
memory: 8036kb

input:

200 1000
200 164 902271 53884170
200 56 160646 471284489
118 17 548821 676285924
75 86 463453 741371140
124 183 677876 745454313
78 118 829257 377444281
26 137 315614 193865748
191 39 355032 923063487
29 171 281727 396954281
147 105 785551 455760667
161 19 730891 528269519
144 49 352247 321053381
15...

output:

2726883

result:

wrong answer 1st lines differ - expected: '2797127', found: '2726883'

Subtask #2:

score: 0
Time Limit Exceeded

Test #17:

score: 0
Time Limit Exceeded

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
Time Limit Exceeded

Test #31:

score: 21
Accepted
time: 160ms
memory: 5996kb

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:

0

result:

ok single line: '0'

Test #32:

score: 21
Accepted
time: 11ms
memory: 8040kb

input:

200 250
72 162 0 953534115
152 94 0 541492633
58 118 0 389246378
118 137 0 266112508
21 100 0 546059320
26 28 0 396924657
155 69 0 955241958
123 102 0 483117471
160 39 0 787307136
31 80 0 230131728
33 69 0 459221426
149 126 0 356240138
128 99 0 991905541
7 57 0 28752914
149 6 0 761950451
23 150 0 66...

output:

-1

result:

ok single line: '-1'

Test #33:

score: 0
Time Limit Exceeded

input:

200 39000
5 128 0 263267641
153 85 0 899842112
187 180 0 595861423
104 180 0 342805606
46 128 0 402084500
149 35 0 569501214
103 161 0 260423816
141 134 0 45988579
46 84 0 733407435
102 72 0 411807981
16 93 0 653975947
136 122 0 802943341
194 12 0 486663003
15 39 0 756041482
114 102 0 81270200
29 17...

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%