QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#780757#5081. Forbidden TurnsvwxyzWA 0ms3852kbC++231.6kb2024-11-25 13:00:082024-11-25 13:00:08

Judging History

This is the latest submission verdict.

  • [2024-11-25 13:00:08]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3852kb
  • [2024-11-25 13:00:08]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using ll=long long;

struct TupleHash {
    template <typename T>
    size_t operator()(const T& tuple) const {
        size_t hash = 0;
        std::apply([&hash](auto&&... args) {
            ((hash ^= std::hash<std::decay_t<decltype(args)>>{}(args) + 0x9e3779b9 + (hash << 6) + (hash >> 2)), ...);
        }, tuple);
        return hash;
    }
};

int main(){
    int M,N,K;
    cin>>M>>N>>K;
    int s,t;cin>>s>>t;
    vector<vector<pair<int,int>>> graph(N);
    for(int m=0;m<M;m++){
        int a,b,c;cin>>a>>b>>c;
        graph[a].emplace_back(b,c);
    }
    unordered_set<tuple<int,int,int>,TupleHash> forbidden;
    for(int k=0;k<K;k++){
        int a,b,c;cin>>a>>b>>c;
        forbidden.emplace(a,b,c);
    }
    int inf=1<<30;
    unordered_map<tuple<int,int>,int,TupleHash> dist;
    for(int x=0;x<N;x++){
        for(auto [y,c]:graph[x]){
            dist[{x,y}]=inf;
        }
    }
    priority_queue<tuple<int,int,int>> queue;
    for(auto [y,c]:graph[s]){
        dist[{s,y}]=c;
        queue.emplace(-c,s,y);
    }
    while(!queue.empty()){
        auto [d,x,y]=queue.top();
        queue.pop();
        d=-d;
        for(auto [z,c]:graph[y]){
            if(forbidden.count({x,y,z})){
                continue;
            }
            if(c+d<dist[{y,z}]){
                dist[{y,z}]=c+d;
                queue.push({-(c+d),y,z});
            }
        }
    }
    int ans=inf;
    for(auto [p,d]:dist){
        if(get<1>(p)==t){
            ans=min(ans,d);
        }
    }
    if(ans==inf){
        ans=-1;
    }
    cout<<ans<<"\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3780kb

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: 3608kb

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: 3852kb

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: 3608kb

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: 3540kb

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: 3584kb

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: 3544kb

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: 3808kb

input:

0 1 0
0 0

output:

-1

result:

wrong answer 1st lines differ - expected: '0', found: '-1'