Submission #983870

#TimeUsernameProblemLanguageResultExecution timeMemory
983870Halym2007Cyberland (APIO23_cyberland)C++17
44 / 100
33 ms12004 KiB
#include <bits/stdc++.h> #include "cyberland.h" using namespace std; #define ff first #define ss second #define pb push_back #define sz size() #define ll long long const int N = 1e5 + 5; vector <pair <int, ll>> v[N]; ll dis[N]; bool vis[N]; void dfs (int x) { vis[x] = 1; for (pair <int, ll> i : v[x]) { if (vis[i.ff]) continue; dfs (i.ff); } } double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { for (int i = 0; i < M; ++i) { // cout << i << " --> " << x[i] << " " << y[i]; v[x[i]].pb ({y[i], (ll)c[i]}); v[y[i]].pb ({x[i], (ll)c[i]}); } for (int i = 0; i < N; ++i) { dis[i] = 1e18; } vis[H] = 1; dfs (0); vis[H] = 0; priority_queue <pair <ll, int>, vector <pair <ll, int>>, greater <pair <ll, int>>> q; q.push ({0, H}); dis[H] = 0; while (!q.empty()) { int x = q.top().ss; q.pop(); for (pair <int, ll> i : v[x]) { if (dis[i.ff] > dis[x] + i.ss) { dis[i.ff] = dis[x] + i.ss; q.push({dis[i.ff], i.ff}); } } } // for (int i = 0; i < N; ++i) { // cout << i << " -- > " << dis[i] << " " << vis[i] << "\n"; // } // exit(0); double jogap; if (dis[0] != 1e18) { jogap = dis[0]; for (int i = 1; i < N; ++i) { if (!arr[i] and vis[i]) { jogap = min (jogap, (double)dis[i]); } } } else { jogap = -1; } for (int i = 0; i < N; ++i) { v[i].clear(); vis[i] = 0; } return jogap; } //int main() { // freopen ("input.txt", "r", stdin); // int T; // assert(1 == scanf("%d", &T)); // while (T--) { // int N,M,K,H; // assert(4 == scanf("%d %d %d\n%d", &N, &M, &K, &H)); // std::vector<int> x(M); // std::vector<int> y(M); // std::vector<int> c(M); // std::vector<int> arr(N); // for (int i=0;i<N;i++) // assert(1 == scanf("%d", &arr[i])); // for (int i=0;i<M;i++) // assert(3 == scanf("%d %d %d", &x[i], &y[i], &c[i])); // printf("%.12lf\n", solve(N, M, K, H, x, y, c, arr)); // } //}
#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...