Submission #1202873

#TimeUsernameProblemLanguageResultExecution timeMemory
1202873zh_hCyberland (APIO23_cyberland)C++17
49 / 100
966 ms2162688 KiB
#include<bits/stdc++.h> #define pb push_back using namespace std; double solve (int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { vector<vector<pair<int, double>>> edge(N); for (int i = 0; i < M; i ++) { edge[x[i]].pb({y[i], c[i]}); edge[y[i]].pb({x[i], c[i]}); } int num_of_2 = 0; for (int i = 0; i < N; i ++) if (arr[i] == 2) num_of_2 ++; bool cal_k = true; vector<vector<bool>> visited(N, vector<bool>(K+1, false)); queue<int> q; q.push(0); while (!q.empty()) { int v = q.front(); q.pop(); if (v == H) continue; for (auto [u, w] : edge[v]) { if (visited[u][0]) continue; visited[u][0] = true; q.push(u); } } priority_queue<pair<double, pair<int, int>>> pq; vector<vector<double>> dist; // if (!cal_k) {dist.resize(N, vector<double>(1, 1e19));} // else {dist.resize(N, vector<double>(K+1, 1e19));} dist.resize(N, vector<double>(K+1, 1e19)); // dist[i][t] = min cost to reach to node i with t times of power 2 ability used dist[0][0] = 0; pq.push({0, {0, 0}}); // {-w, {v, k}} // cout << "zeros: " << endl; for (int i = 1; i < N; i ++) { // cout << arr[i] << "cc"; if (arr[i] == 0 && visited[i][0]) { // cout << i << endl; pq.push({0, {i, 0}}); dist[i][0] = 0; } } visited.clear(); visited.resize(N, vector<bool>(K+1, false)); while (!pq.empty()) { // priority_queue<pair<double, pair<int, int>>> pq_temp = pq; // cout << "pq_temp: " << endl; // while (!pq_temp.empty()){ // cout << pq_temp.top().second.first << " " << pq_temp.top().second.second << endl; // pq_temp.pop(); // } // cout << endl; int v = pq.top().second.first, k = pq.top().second.second; pq.pop(); if (v == H) continue; // if (visited[v]) continue; visited[v][k] = true; for (auto [u, w] : edge[v]) { // if (visited[u][k]) continue; // if (cal_k) { if (dist[v][k] + w < dist[u][k] && !visited[u][k]) { dist[u][k] = dist[v][k] + w; pq.push({ (dist[u][k]*(-1)) , {u, k} }); } if (arr[u] == 2 && k+1 <= K) { if ( (dist[v][k] + w)/2 < dist[u][k+1] && !visited[u][k+1]) { dist[u][k+1] = (dist[v][k] + w)/2; pq.push({ (dist[u][k+1]*(-1)), {u, k+1} }); } } // } // else { // if (arr[u] == 2) { // if ( (dist[v][k] + w)/2 < dist[u][k]) { // dist[u][k] = (dist[v][k] + w)/2; // pq.push({ (dist[u][k]*(-1)), {u, k} }); // } // } // else { // if (dist[v][k] + w < dist[u][k]) { // dist[u][k] = dist[v][k] + w; // pq.push({ (dist[u][k]*(-1)) , {u, k}}); // } // } // } } } // cout << "dist: " << endl; // for (int i = 0; i < N; i ++) { // cout << i << ": "; // for (auto j : dist[i]) { // cout << j << " "; // } // cout << endl; // } double mn = 1e19; for (int i = 0; i <= K; i ++) { mn = min(mn, dist[H][i]); } if (mn == 1e19) {return (double)-1;} return (double)mn; }
#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...