Submission #756810

#TimeUsernameProblemLanguageResultExecution timeMemory
756810dooweyCyberland (APIO23_cyberland)C++17
15 / 100
38 ms8908 KiB
#include <bits/stdc++.h> #include "cyberland.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<double, int> pdi; #define fi first #define se second #define mp make_pair const int N = (int)1e5 + 10; const int K = 65; vector<pii> T[N]; struct state{ double dist; int cnt; int idx; bool operator< (const state &si) const { if(idx == si.idx){ if(cnt == si.cnt){ return dist > si.dist; } else{ return cnt < si.cnt; } } else{ return dist > si.dist; } } }; bool can[N]; bool vv[N]; int A[N]; void dfs(int u){ vv[u]=true; if(u == 0 || A[u] == 0) can[u] = true; for(auto x : T[u]){ if(!vv[x.fi]){ dfs(x.fi); } } } double d[K][N]; bool vis[K][N]; double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { k = min(k, 60); for(int i = 0 ; i < n; i ++ ){ T[i].clear(); can[i] = vv[i] = false; A[i] = arr[i]; } for(int i = 0 ; i < m ; i ++ ){ T[x[i]].push_back(mp(y[i], c[i])); T[y[i]].push_back(mp(x[i], c[i])); } dfs(0); double dis; double nw; double op = 1e18; bool fix = false; for(int j = 0 ; j < 1 ; j ++ ){ for(int i = 0 ; i < n; i ++ ){ d[j][i] = 1e18; vis[j][i] = false; } priority_queue<pdi, vector<pdi>, greater<pdi>> pq; if(j == 0){ d[j][h] = 0.0; pq.push(mp(0.0, h)); } else{ for(int i = 0 ; i < n; i ++ ){ if(vis[j - 1][i] && A[i] == 2){ pq.push(mp(i, d[j - 1][i])); } } } while(!pq.empty()){ int node = pq.top().se; dis = pq.top().fi; pq.pop(); if(vis[j][node]) continue; vis[j][node] = true; if(can[node]){ op = min(op, dis); fix = true; } for(auto x : T[node]){ nw = x.se; if(dis + nw < d[j][x.fi]){ d[j][x.fi] = dis + nw; pq.push(mp(d[j][x.fi], x.fi)); } } } } if(fix) return op; return -1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...