QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#533432 | #5081. Forbidden Turns | JanganLupaDaftarArkavidia# | WA | 5ms | 20204kb | C++20 | 2.2kb | 2024-08-25 23:00:05 | 2024-08-25 23:00:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
struct node{
ll D; int cur, pr;
bool operator < (const node &other) const {
return D < other.D;
}
};
vector<pair<int, ll>> adj[30001];
vector<int> bef[30001];
set<int> forbidden[30001][10];
bool vis[30001][11];
ll dist[30001][11];
void solve(){
int M, N, F; cin >> M >> N >> F;
int st, ed; cin >> st >> ed;
for(int i = 1; i <= M; ++i){
int u, v; ll w; cin >> u >> v >> w;
adj[v].push_back({u, w});
bef[u].push_back(v);
}
for(int i = 0; i < N; ++i){
sort(bef[i].begin(), bef[i].end());
for(int j = 0; j < (int)bef[i].size(); ++j){
dist[i][j] = 1e18;
}
}
for(int i = 1; i <= F; ++i){
int x, y, z; cin >> x >> y >> z;
int index = lower_bound(bef[y].begin(), bef[y].end(), z) - bef[y].begin();
forbidden[y][index].insert(x);
}
if(st == ed){
cout << "0\n";
return;
}
priority_queue<node> pq;
pq.push({0, ed, 10});
dist[ed][10] = 0;
while(!pq.empty()){
ll D = pq.top().D; int cur = pq.top().cur, pr = pq.top().pr;
pq.pop();
if(vis[cur][pr]){
continue;
}
vis[cur][pr] = 1;
//cout << D << " " << cur << " " << pr << "\n";
for(auto nx : adj[cur]){
int to = nx.first; ll len = nx.second;
int index = lower_bound(bef[to].begin(), bef[to].end(), cur) - bef[to].begin();
if(!forbidden[cur][pr].count(to)){
if(dist[to][index] > D + len){
dist[to][index] = D + len;
pq.push({dist[to][index], to, index});
}
}
}
}
ll answer = 1e18;
for(int i = 0; i < (int)bef[st].size(); ++i){
answer = min(answer, dist[st][i]);
}
cout << (answer >= 1e18 ? -1 : answer) << "\n";
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int tc = 1; //cin >> tc;
while(tc--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 20000kb
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: 20136kb
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: 20164kb
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: 20204kb
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: -100
Wrong Answer
time: 2ms
memory: 20000kb
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:
82
result:
wrong answer 1st lines differ - expected: '63', found: '82'