QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#532714 | #5081. Forbidden Turns | BongoCatEnjoyer# | WA | 0ms | 3508kb | C++14 | 1.9kb | 2024-08-25 10:07:10 | 2024-08-25 10:07:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define forn(i, n) for (ll i = 0; i < n; ++i)
#define forr(i, s, n) for (ll i = s; i < n; ++i)
#define fori(i, s, n) for (ll i = s; i > n; --i)
#define fora(i, n) for (auto i: n)
#define vi vector<int>
#define vll vector<ll>
#define prints(n) cout << (n) << " "
#define println(n) cout << (n) << "\n"
const int MOD = 998244353;
// const int MOD = 1e9 + 7;
void solve() {
ll m, n, k; cin >> m >> n >> k;
ll s, t; cin >> s >> t;
vector<vector<pair<ll, ll>>> adj(n, vector<pair<ll, ll>>());
map<pair<ll, ll>, ll> mp;
forn(i, m) {
ll u, v, w; cin >> u >> v >> w;
adj[u].push_back({v, w});
mp[{u, v}] = i;
}
set<tuple<ll, ll, ll>> st;
forn(i, k) {
ll a, b, c; cin >> a >> b >> c;
st.insert({a, b, c});
}
// Tuple -Dist, Curr, Prev
priority_queue<tuple<ll, ll, ll>> pq;
pq.push({0, s, -1});
ll ans = -1;
vector<bool> visn(n), vise(m);
while (!pq.empty()) {
auto [dist, curr, prev] = pq.top(); pq.pop();
// prints(dist); prints(curr); println(prev);
if (curr == t) {
ans = -dist; break;
}
if (visn[curr]) continue;
visn[curr] = true;
fora(edge, adj[curr]) {
ll next = edge.first, cost = edge.second;
if (!visn[next]) continue;
if (vise[mp[{curr, next}]]) continue;
if (st.find({prev, curr, next}) != st.end()) {
visn[curr] = false; continue;
}
pq.push({dist - cost, next, curr});
}
}
println(ans);
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3508kb
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:
-1
result:
wrong answer 1st lines differ - expected: '36', found: '-1'