QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#176782 | #5081. Forbidden Turns | nathanlee726 | WA | 1ms | 4572kb | C++17 | 1.9kb | 2023-09-12 00:38:08 | 2023-09-12 00:38:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i, l, n) for(int i = l; i < n; i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define endl '\n'
#ifdef LOCAL
#define debug(args...) LKJ("\033[1;32m["#args"]\033[0m", args)
template<class I> void LKJ(I&&x) { cerr << x << endl; }
template<class I, class ...T> void LKJ(I&&x, T&&...t)
{ cerr << x << ", ", LKJ(t...);}
#else
#define debug(...) ((void)0)
#endif
set<pair<pii,int > > fb;
vector<pii> g[30010];
map<pii, int> dis;
int main(){
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n, m, k, s, t;
cin >> m >> n >> k;
cin >> s >> t;
rep(i, 0, m){
int x, y, w;
cin >> x >> y >> w;
g[x].push_back({y, w});
//g[y].push_back({x, w});
}
rep(i, 0, k){
int x, y, z;
cin >> x >> y >> z;
//--x, --y, --z;
fb.insert({{x, y}, z});
}
dis[make_pair(-1, s)] = 0;
priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<pair<int, pii>> > pq;
pq.push({0, {-1, s}});
while(!pq.empty()){
auto pt = pq.top();pq.pop();
if(dis[pt.second] < pt.first) continue;
for(auto ptt: g[pt.second.second]){
if(fb.count({pt.second, ptt.first})) continue;
if((!dis.count({pt.second.second, ptt.first})) || dis[make_pair(pt.second.second, ptt.first)] > pt.first + ptt.second){
dis[make_pair(pt.second.second, ptt.first)] = pt.first + ptt.second;
pq.push({dis[make_pair(pt.second.second, ptt.first)], {pt.second.second, ptt.first}});
}
}
}
int ans = 1e9;
for(auto tmp: dis)
if(tmp.first.second == t)ans = min(ans, tmp.second);
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4344kb
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: 4276kb
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: 1ms
memory: 4348kb
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: 4280kb
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: 4572kb
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: 1ms
memory: 4280kb
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:
1000000000
result:
wrong answer 1st lines differ - expected: '-1', found: '1000000000'