QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#142074 | #5081. Forbidden Turns | 8BQube# | WA | 2ms | 7552kb | C++20 | 1.6kb | 2023-08-18 13:47:19 | 2023-08-18 13:47:24 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define SZ(a) ((int)a.size())
const ll INF = 1e18;
struct Edge {
int u, v, w;
} edges[300005];
vector<int> G[30005];
ll dis[300005];
unordered_set<ll> ban;
ll num(ll a, ll b, ll c) {
const ll P = 100000;
return a * P * P + b * P + c;
}
bool valid(ll a, ll b, ll c) {
return ban.find(num(a, b, c)) == ban.end();
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, m, k, s, t;
cin >> m >> n >> k >> s >> t, ++s, ++t;
for (int i = 1; i <= m; ++i) {
cin >> edges[i].u >> edges[i].v >> edges[i].w;
++edges[i].u, ++edges[i].v;
G[edges[i].u].pb(i);
}
while (k--) {
int a, b, c;
cin >> a >> b >> c;
ban.insert(num(a + 1, b + 1, c + 1));
}
priority_queue<pll, vector<pll>, greater<pll>> pq;
fill_n(dis + 1, m, INF);
auto relax = [&](int e, ll d) {
if (dis[e] > d) {
dis[e] = d;
pq.push(pll(d, e));
}
};
for (int e : G[s])
relax(e, edges[e].w);
while (!pq.empty()) {
auto [d, e] = pq.top();
pq.pop();
if (dis[e] != d) continue;
for (int i : G[edges[e].v])
if (valid(edges[e].u, edges[e].v, edges[i].v))
relax(i, dis[e] + edges[i].w);
}
ll ans = INF;
for (int i = 1; i <= m; ++i)
if (edges[i].v == t)
ans = min(ans, dis[i]);
if (ans == INF) cout << "-1\n";
else cout << ans << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5508kb
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: 2ms
memory: 5508kb
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: 7552kb
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: 1ms
memory: 5636kb
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: 2ms
memory: 5576kb
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: 7552kb
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: 5584kb
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: 0ms
memory: 5500kb
input:
0 1 0 0 0
output:
-1
result:
wrong answer 1st lines differ - expected: '0', found: '-1'