QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#508111 | #5081. Forbidden Turns | stasio6 | WA | 2ms | 8016kb | C++14 | 1.9kb | 2024-08-07 03:21:33 | 2024-08-07 03:21:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back
#define FS first
#define SD second
#define ary(k) array<int,k>
template<class A,class B> void cmx(A& x, B y) {x=max<A>(x,y);}
template<class A,class B> void cmn(A& x, B y) {x=min<A>(x,y);}
typedef pair<int, int> pii;
typedef vector<int> vi;
int dist[100002][11];
vector<pii> kra[100002];
signed main() {
cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit);
int n, m, q;
cin >> m >> n >> q;
int s, t;
cin >> s >> t;
for (int i = 0; i <= n; i++) {
for (int j = 0; j < 10; j++) {
dist[i][j] = 1000000000000000001ll;
}
}
for (int i = 0; i < m; i++) {
int u, v, w;
cin >> u >> v >> w;
kra[u].PB({v, w});
}
set<array<int, 3>> forbidden;
for (int i = 0; i < q; i++) {
int a, b, c;
cin >> a >> b >> c;
forbidden.insert({a, b, c});
}
kra[n].PB({s, 0});
dist[n][0] = 0;
priority_queue<array<int, 3>, vector<array<int, 3>>, greater<array<int, 3>>> pq;
pq.push({0, n, 0});
int best = 1000000000000000001ll;
while (!pq.empty()) {
auto [d, v, nv] = pq.top();
pq.pop();
if (d > dist[v][nv])
continue;
int u = kra[v][nv].FS;
for (int i = 0; i < sz(kra[u]); i++) {
auto [nu, nw] = kra[u][i];
if (forbidden.find({v, u, nu}) != forbidden.end())
continue;
int nd = d + nw;
if (nd < dist[u][i]) {
dist[u][i] = nd;
pq.push({nd, u, i});
if (nu == t)
cmn(best, nd);
}
}
}
if (best == 1000000000000000001ll)
best = -1;
cout << best << "\n";
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 7084kb
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: 1ms
memory: 8016kb
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: 2ms
memory: 6460kb
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: 7808kb
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: 1ms
memory: 6984kb
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: 1ms
memory: 6396kb
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: 2ms
memory: 7876kb
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: -100
Wrong Answer
time: 2ms
memory: 7536kb
input:
0 1 0 0 0
output:
-1
result:
wrong answer 1st lines differ - expected: '0', found: '-1'