Submission #720257

# Submission time Handle Problem Language Result Execution time Memory
720257 2023-04-07T18:37:51 Z Ahmed57 Ceste (COCI17_ceste) C++14
160 / 160
541 ms 25272 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long
long long cost[2005];
long long ti[2005];
vector<pair<int,pair<int,int>>> adj[2005];
signed main(){
    int n,m;
    cin>>n>>m;
    for(int i = 0;i<m;i++){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        adj[a].push_back({b,{c,d}});
        adj[b].push_back({a,{c,d}});
    }
    for(int i = 2;i<=n;i++){
        cost[i] = 1e15;
        ti[i] = 1e15;
    }
    priority_queue<pair<int,pair<int,int>>> q;
    q.push({0,{0,1}});
    while(!q.empty()){
        int no = q.top().second.second;
        int fi = q.top().second.first;
        int se = -q.top().first;
        q.pop();
        cost[no] = min(cost[no],fi*se);
        if(ti[no]<fi)continue;
        ti[no] = fi;
        for(auto j:adj[no]){
            if(fi+j.second.first>4000005)continue;
            q.push({-(se+j.second.second),{fi+j.second.first,j.first}});
        }
    }
    for(int i = 2;i<=n;i++){
        long long ans = cost[i];
        if(ans==1e15){
            cout<<"-1"<<endl;
        }
        else cout<<ans<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 468 KB Output is correct
2 Correct 6 ms 616 KB Output is correct
3 Correct 6 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 1996 KB Output is correct
2 Correct 58 ms 3640 KB Output is correct
3 Correct 68 ms 3788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 177 ms 3684 KB Output is correct
2 Correct 541 ms 25272 KB Output is correct
3 Correct 8 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 1388 KB Output is correct
2 Correct 339 ms 12936 KB Output is correct
3 Correct 14 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 234 ms 1380 KB Output is correct
2 Correct 222 ms 3720 KB Output is correct
3 Correct 209 ms 3740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 195 ms 3648 KB Output is correct
2 Correct 192 ms 3692 KB Output is correct
3 Correct 266 ms 3684 KB Output is correct