Submission #1084342

# Submission time Handle Problem Language Result Execution time Memory
1084342 2024-09-06T02:38:48 Z Equinox Ceste (COCI17_ceste) C++17
96 / 160
2500 ms 856 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef complex<double> cpx;
#define fastio cin.tie(0)->sync_with_stdio(0); cout.tie(0);
#define all(x) x.begin(),x.end()
#define compress(x) x.erase(unique(all(x)),x.end())
#define ff first
#define ss second

struct Edge{
    ll x,t,c;
};

ll n,m,dist[2010];
pll dsum[2010];
vector<Edge> g[2010];

ll ans = (ll)1e15;

pll dijkstra(ll x, ll a, ll b){
    for(int i=1;i<=n;i++){
        dist[i] = (ll)1e15;
        dsum[i] = {(ll)1e15,(ll)1e15};
    }
    dist[1] = 0;
    dsum[1] = {0,0};
    priority_queue<pair<pll,pll> > pq;
    pq.push({{0,1},{0,0}});
    while(!pq.empty()){
        ll c = pq.top().ff.ss, w = -pq.top().ff.ff;
        ll ca = pq.top().ss.ff, cb = pq.top().ss.ss;
        pq.pop();
        if(dist[c]<w) continue;
        for(auto i:g[c]){
            ll nx = i.x, nw = w + a*i.t + b*i.c;
            ll na = ca + i.t, nb = cb + i.c;
            if(nw<dist[nx]){
                dist[nx] = nw;
                dsum[nx] = {na,nb};
                //cout << i.x << " " << c << " " << nx << "\n";
                pq.push({{-dist[nx],nx},{na,nb}});
            }
        }
    }
    if(dist[x]>(ll)1e14) return dsum[x];
    else{
        ans = min(ans,dsum[x].ff*dsum[x].ss);
        return dsum[x];
    }
}

void qhull(ll x, pll a, pll b){
    pll c = dijkstra(x,a.ss-b.ss,b.ff-a.ff);
    if((b.ff-a.ff)*(c.ss-a.ss)==(b.ss-a.ss)*(c.ff-a.ff)) return;
    qhull(x,a,c); qhull(x,c,b);
}

ll solve(ll x){
    ans = (ll)1e18;
    pll lc = dijkstra(x,1,0);
    pll rc = dijkstra(x,0,1);
    // cout << lc.ff << " " << lc.ss << "\n";
    // cout << rc.ff << " " << rc.ss << "\n";
    if(lc.ff>(ll)1e14) return -1;
    qhull(x,lc,rc);
    return ans;
}

int main(){
    fastio;
    cin >> n >> m;
    for(int i=0;i<m;i++){
        ll x,y,z,w; cin >> x >> y >> z >> w;
        g[x].push_back({y,z,w});
        g[y].push_back({x,z,w});
    }
    for(int i=2;i<=n;i++){
        cout << solve(i) << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 386 ms 604 KB Output is correct
2 Correct 192 ms 600 KB Output is correct
3 Correct 24 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 326 ms 564 KB Output is correct
2 Correct 191 ms 348 KB Output is correct
3 Correct 105 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2530 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2602 ms 728 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2556 ms 736 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2547 ms 604 KB Time limit exceeded
2 Halted 0 ms 0 KB -