QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#532727 | #5081. Forbidden Turns | BongoCatEnjoyer# | WA | 0ms | 3884kb | C++14 | 2.0kb | 2024-08-25 10:33:26 | 2024-08-25 10:33:26 |
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;
}
map<pair<int, int>, set<int>> forb;
forn(i, k) {
ll a, b, c; cin >> a >> b >> c;
if (forb.find({a, b}) == forb.end()) forb[{a, b}] = set<int>();
forb[{a, b}].insert(c);
}
priority_queue<pair<int, pair<int, int>>> pq;
pq.push({0, {-1, s}});
set<int> vis[n+5];
while (!pq.empty()) {
pair<int, pair<int, int>> p = pq.top();
int w = p.first;
int prev = p.second.first;
int cur = p.second.second;
pq.pop();
if (cur == t) {
cout << -w << '\n';
return;
}
if (vis[cur].count(prev) || vis[cur].count(-1)) {
continue;
}
if (forb.count({prev, cur})) {
vis[cur].insert(prev);
}
else {
vis[cur].insert(-1);
}
set<int> curforb = forb[{prev, cur}];
for(auto x: adj[cur]) {
if (curforb.count(x.first)) continue;
pq.push({w - x.second, {cur, x.first}});
}
}
}
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: 100
Accepted
time: 0ms
memory: 3588kb
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: 3640kb
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: 3688kb
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: 3884kb
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: 3648kb
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: -100
Wrong Answer
time: 0ms
memory: 3656kb
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:
result:
wrong answer 1st lines differ - expected: '-1', found: ''