QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#743009 | #5081. Forbidden Turns | ucup-team5062# | WA | 36ms | 6844kb | C++20 | 1.8kb | 2024-11-13 17:55:26 | 2024-11-13 17:55:27 |
Judging History
answer
#include <array>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 1012345678;
struct state {
int pos, cost;
bool operator<(const state& s) const {
return cost > s.cost;
}
};
int main() {
// step #1. input
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N, M, K, S, T;
cin >> M >> N >> K >> S >> T;
vector<int> A(M), B(M), C(M);
for (int i = 0; i < M; i++) {
cin >> A[i] >> B[i] >> C[i];
}
vector<array<int, 3> > ban(K);
for (int i = 0; i < N; i++) {
cin >> ban[i][0] >> ban[i][1] >> ban[i][2];
}
// step #2. construct graph
vector<vector<int> > G(N);
for (int i = 0; i < M; i++) {
G[A[i]].push_back(i);
}
// step #3. search ban
sort(ban.begin(), ban.end());
auto banned = [&](int x, int y, int z) -> bool {
return binary_search(ban.begin(), ban.end(), array<int, 3>({x, y, z}));
};
// step #4. dijkstra
vector<int> d(M, INF);
priority_queue<state> que;
for (int i = 0; i < M; i++) {
if (A[i] == S) {
d[i] = C[i];
que.push(state{i, C[i]});
}
}
int ans = (T != S ? INF : 0);
while (!que.empty()) {
state z = que.top();
que.pop();
if (B[z.pos] == T) {
ans = min(ans, z.cost);
}
if (d[z.pos] == z.cost) {
for (int id : G[B[z.pos]]) {
if (!banned(A[z.pos], B[z.pos], B[id]) && d[id] > z.cost + C[id]) {
d[id] = z.cost + C[id];
que.push(state{id, d[id]});
}
}
}
}
// step #5. output
cout << (ans != INF ? ans : -1) << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
input:
9 7 3 3 2 6 3 2 3 0 3 0 1 12 1 0 4 1 2 2 1 5 4 4 1 8 5 4 7 5 2 5 0 1 2 4 1 5 1 5 2
output:
36
result:
ok single line: '36'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3420kb
input:
4 4 1 0 3 0 1 2 1 2 3 0 2 7 2 3 10 0 1 2
output:
17
result:
ok single line: '17'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
4 4 0 0 3 0 1 2 1 2 3 0 2 7 2 3 10
output:
15
result:
ok single line: '15'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
4 4 1 1 0 1 2 3 2 3 10 3 2 12 2 0 7 1 2 0
output:
32
result:
ok single line: '32'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3472kb
input:
13 8 5 0 5 0 2 3 2 1 7 4 2 10 2 3 10 3 2 12 2 5 10 3 6 10 6 7 5 7 3 5 6 4 10 4 1 0 1 4 10 4 6 10 0 2 1 0 2 5 3 2 5 2 3 2 6 4 2
output:
63
result:
ok single line: '63'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
4 4 2 1 0 1 2 3 2 3 10 3 2 12 2 0 7 1 2 0 2 3 2
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
4 4 0 1 0 1 2 3 2 3 2 3 2 3 2 0 7
output:
10
result:
ok single line: '10'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
0 1 0 0 0
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 21ms
memory: 6028kb
input:
59996 30000 29997 0 29999 0 1 3 1 29999 7 1 2 1 2 1 1 2 3 1 3 2 1 3 4 1 4 3 1 4 5 1 5 4 1 5 6 1 6 5 1 6 7 1 7 6 1 7 8 1 8 7 1 8 9 1 9 8 1 9 10 1 10 9 1 10 11 1 11 10 1 11 12 1 12 11 1 12 13 1 13 12 1 13 14 1 14 13 1 14 15 1 15 14 1 15 16 1 16 15 1 16 17 1 17 16 1 17 18 1 18 17 1 18 19 1 19 18 1 19 2...
output:
60004
result:
ok single line: '60004'
Test #10:
score: -100
Wrong Answer
time: 36ms
memory: 6844kb
input:
54776 10000 149059 0 9999 0 1168 720 0 7849 347 0 5301 937 0 1176 113 0 4762 833 0 6595 630 0 5846 548 0 528 878 1 3794 680 1 5036 171 1 4938 977 1 3180 522 1 9790 3 1 2139 221 1 3003 470 2 1054 534 2 5405 899 2 8279 740 2 1749 864 2 4634 773 2 7027 960 2 8151 321 2 4893 201 3 960 939 4 2349 671 5 6...
output:
1536
result:
wrong answer 1st lines differ - expected: '2041', found: '1536'