Submission #720245

# Submission time Handle Problem Language Result Execution time Memory
720245 2023-04-07T17:52:52 Z Ahmed57 Ceste (COCI17_ceste) C++14
64 / 160
2500 ms 131072 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long
unordered_map<long long,long long> cost[2005];
unordered_map<long long,long long> vis[2005];
vector<pair<int,pair<int,int>>> adj[2005];
signed main(){
    int n,m;
    cin>>n>>m;
    //if(n<=100)assert(0);
    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}});
    }
    priority_queue<pair<int,pair<int,int>>> q;
    q.push({0,{0,1}});
    cost[1][0]=0;
    vis[1][0] = 1;
    while(!q.empty()){
        int no = q.top().second.second;
        int se = q.top().second.first;
        int co = -q.top().first;
        q.pop();
        if(cost[no][se]<co)continue;
        for(auto j:adj[no]){
            if(se+j.second.first>10004)continue;
            if(!vis[j.first][se+j.second.first]||cost[j.first][se+j.second.first]>co+j.second.second){
                cost[j.first][se+j.second.first] =  co+j.second.second;
                vis[j.first][se+j.second.first] = 1;
                q.push({-cost[j.first][se+j.second.first],{se+j.second.first,j.first}});
            }
        }
    }
    for(int i = 2;i<=n;i++){
        long long ans = 1e15;
        for(auto j:vis[i]){
            ans = min(ans,j.first*cost[i][j.first]);
        }
        if(ans==1e15){
            cout<<"-1"<<endl;
        }
        else cout<<ans<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 82 ms 8400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 491 ms 51588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 527 ms 28260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 362 ms 42596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1381 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2566 ms 121980 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 799 ms 51912 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 512 ms 38580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 243 ms 22812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 986 ms 52056 KB Output isn't correct
2 Halted 0 ms 0 KB -