답안 #748318

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
748318 2023-05-26T06:04:17 Z Pacybwoah Olympic Bus (JOI20_ho_t4) C++17
26 / 100
1000 ms 6432 KB
#include<iostream>
#include<vector>
#include<queue>
#include<set>
#define ll long long
using namespace std;
int n,m;
set<int> crit;
vector<pair<pair<int,int>,pair<ll,ll>>> edges;
vector<ll> dijk(vector<vector<pair<pair<int,int>,pair<ll,ll>>>> &g,int s,int skip,bool flag){
    vector<ll> dist(n+1,1e18);
    dist[s]=0;
    priority_queue<pair<int,ll>,vector<pair<int,ll>>,greater<pair<int,ll>>> pq;
    pq.push(make_pair(0,s));
    while(!pq.empty()){
        auto node=pq.top();
        pq.pop();
        if(dist[node.second]<node.first) continue;
        for(auto x:g[node.second]){
            if(x.first.second==skip) continue;
            if(dist[x.first.first]>dist[node.second]+x.second.first){
                if(flag) crit.insert(x.first.second);
                dist[x.first.first]=dist[node.second]+x.second.first;
                pq.push(make_pair(dist[x.first.first],x.first.first));
            }
        }
        if(skip!=-1&&edges[skip].first.second==node.second){
            if(dist[edges[skip].first.first]>dist[node.second]+edges[skip].second.first){
                dist[edges[skip].first.first]=dist[node.second]+edges[skip].second.first;
                pq.push(make_pair(dist[edges[skip].first.first],edges[skip].first.first));
            }
        }
    }
    return dist;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c,d;
    cin>>n>>m;
    vector<vector<pair<pair<int,int>,pair<ll,ll>>>> graph(n+1),hparg(n+1);
    for(int i=0;i<m;i++){
        cin>>a>>b>>c>>d;
        edges.push_back(make_pair(make_pair(a,b),make_pair(c,d)));
        graph[a].push_back(make_pair(make_pair(b,i),make_pair(c,d)));
        hparg[b].push_back(make_pair(make_pair(a,i),make_pair(c,d)));
    }
    vector<ll> from1,fromn,to1,ton;
    from1=dijk(graph,1,-1,1);
    fromn=dijk(graph,n,-1,1);
    to1=dijk(hparg,1,-1,1);
    ton=dijk(hparg,n,-1,1);
    ll ans=from1[n]+fromn[1];
    for(int i=0;i<m;i++){
        if(crit.count(i)){
            vector<ll> tmp1=dijk(graph,1,i,0),tmp2=dijk(graph,n,i,0);
            ans=min(ans,tmp1[n]+tmp2[1]+edges[i].second.second);
        }
        else{
            ans=min(ans,min(from1[n],from1[edges[i].first.second]+edges[i].second.first+ton[edges[i].first.first])+min(fromn[1],fromn[edges[i].first.second]+edges[i].second.first+to1[edges[i].first.first])+edges[i].second.second);
        }
    }
    if(ans>=1e18) cout<<-1;
    else cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 404 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 31 ms 468 KB Output is correct
4 Correct 36 ms 496 KB Output is correct
5 Correct 6 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 59 ms 468 KB Output is correct
11 Correct 62 ms 488 KB Output is correct
12 Correct 58 ms 480 KB Output is correct
13 Correct 7 ms 476 KB Output is correct
14 Correct 20 ms 468 KB Output is correct
15 Correct 18 ms 492 KB Output is correct
16 Correct 21 ms 496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1077 ms 6432 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 484 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 168 ms 5256 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 188 ms 6044 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 67 ms 6108 KB Output is correct
9 Correct 77 ms 6188 KB Output is correct
10 Correct 129 ms 5900 KB Output is correct
11 Correct 132 ms 6020 KB Output is correct
12 Correct 132 ms 6144 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 132 ms 6124 KB Output is correct
20 Correct 126 ms 6032 KB Output is correct
21 Correct 129 ms 6248 KB Output is correct
22 Correct 132 ms 5832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 404 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 31 ms 468 KB Output is correct
4 Correct 36 ms 496 KB Output is correct
5 Correct 6 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 59 ms 468 KB Output is correct
11 Correct 62 ms 488 KB Output is correct
12 Correct 58 ms 480 KB Output is correct
13 Correct 7 ms 476 KB Output is correct
14 Correct 20 ms 468 KB Output is correct
15 Correct 18 ms 492 KB Output is correct
16 Correct 21 ms 496 KB Output is correct
17 Execution timed out 1077 ms 6432 KB Time limit exceeded
18 Halted 0 ms 0 KB -