Submission #804451

#TimeUsernameProblemLanguageResultExecution timeMemory
804451Theo830Cyberland (APIO23_cyberland)C++17
44 / 100
36 ms9464 KiB
#include "cyberland.h" #include <bits/stdc++.h> using namespace std; #define f(i,a,b) for(int i = a;i < b;i++) #define ll long long #define ii pair<ll,ll> #define F first #define S second #define pb push_back priority_queue<ii,vector<ii>,greater<ii> >pq; bool v[100005] = {0}; ll dist[100005]; vector<vector<ii> >adj; ll H; void dfs(ll idx){ v[idx] = 1; for(auto x:adj[idx]){ if(!v[x.F] && x.F != H){ dfs(x.F); } } } double solve(int n, int m, int k, int h, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr) { double ans; H = h; adj.assign(n+5,vector<ii>()); f(i,0,n){ v[i] = 0; dist[i] = 1e18; } f(i,0,m){ adj[x[i]].pb(ii(y[i],c[i])); adj[y[i]].pb(ii(x[i],c[i])); } dfs(0); f(i,0,n){ if((arr[i] == 0 && v[i]) || i == 0){ pq.push(ii(0,i)); dist[i] = 0; } } while(!pq.empty()){ ii f = pq.top(); pq.pop(); ll w = f.F,u = f.S; if(dist[u] < w){ continue; } for(auto x:adj[u]){ if(dist[x.F] > dist[u] + x.S){ dist[x.F] = dist[u] + x.S; pq.push(ii(dist[x.F],x.F)); } } } ans = dist[h]; if(dist[h] == 1e18){ ans = -1; } return ans; }
#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...