QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#252470 | #5081. Forbidden Turns | NYCU_gAwr_gurA# | WA | 0ms | 3748kb | C++17 | 1.6kb | 2023-11-15 19:56:32 | 2023-11-15 19:56:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define fast
#else
#define fast cin.tie(0)->sync_with_stdio(0)
#define cerr if(1);else cerr
#define endl '\n'
#endif
#define _ <<' '<<
#define ALL(v) v.begin(),v.end()
#define ft first
#define sd second
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
struct Edge {
int u, v, w, dist;
bool visit = false;
set<int> forbid{};
};
constexpr int INF = 1e9;
signed main() {
fast;
int m, n, k;
cin >> m >> n >> k;
int s, t;
cin >> s >> t;
vector<Edge> edge(m);
map<pii, int> mp{};
vector<vector<pii>> G(n);
for (int i = 0; i < m; i++) {
int u, v, w;
cin >> u >> v >> w;
edge[i].u = u;
edge[i].v = v;
edge[i].w = w;
G[u].emplace_back(v, i);
mp[{ u, v }] = i;
}
for (int i = 0; i < k; i++) {
int x, y, z;
cin >> x >> y >> z;
auto it = mp.find({ x, y });
if (it == mp.end()) continue;
if (mp.find({ y, z }) == mp.end()) continue;
edge[it->second].forbid.emplace(z);
}
int ans = -1;
priority_queue<tuple<int,int>> pq{};
auto add = [&](int i, int d) {
edge[i].dist = d += edge[i].w;
edge[i].visit = true;
pq.emplace( -d, i );
};
for (auto [y,i]: G[s])
add(i, 0);
while (!pq.empty()) {
auto [d,i] = pq.top(); pq.pop();
d *= -1;
const auto& e = edge[i];
if (e.v == t) {
ans = e.dist;
break;
}
cerr _ i _ d _ e.u _ e.v _ e.w _ endl;
for (auto [y,j]: G[e.v]) if (!edge[j].visit) {
if (!e.forbid.count(y)) {
add(j, d);
}
}
}
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
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: 3612kb
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: 3588kb
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: 3596kb
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: 3744kb
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: 3612kb
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: 3748kb
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: 3612kb
input:
0 1 0 0 0
output:
-1
result:
wrong answer 1st lines differ - expected: '0', found: '-1'