Submission #1060921

# Submission time Handle Problem Language Result Execution time Memory
1060921 2024-08-16T04:33:34 Z Halym2007 Cyberland (APIO23_cyberland) C++17
0 / 100
424 ms 11604 KB
#include <bits/stdc++.h>
//#include "cyberland.h"
using namespace std;
#define ll long long
#define sz size()
#define ff first
#define ss second
#define pb push_back
#define pii pair <int, int>
const int N = 2e5 + 5;

vector <pii> v[N];
ll dis[N];
priority_queue <pair <ll, int>, vector<pair <ll, int>>, greater <pair <ll, int>>> q;
int n, m, k, h;

double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
	n = N;m = M;k = K;h = H;
	
	for (int i = 0; i < m; ++i) {
		v[x[i]].pb ({y[i], c[i]});
		v[y[i]].pb ({x[i], c[i]});
	}
	
	for (int i = 0; i < n; ++i) {
		dis[i] = 1e16;
	}
	q.push ({0, h});
	dis[h] = 0;
	while (!q.empty()) {
		int x = q.top().ss;
		q.pop();
		for (pii 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});
			}		
		}
	} 
	double jogap = 1e16;
	jogap = min (jogap, (double)dis[0]);
	for (int i = 0; i < n; ++i) {
		if (arr[i] == 0) {
			jogap = min (jogap, (double)dis[i]);
		}
	}
	if (jogap == (double)1e16) jogap = -1;
	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));
//  }
//}


/*
1
3 2 30
2
1 2 1
1 2 12
2 0 4
answer : 4.00000000000

1
4 4 30
3
1 0 2 1
0 1 5
0 2 4
1 3 2
2 3 4
answer : 2.00000000000
*/
# Verdict Execution time Memory Grader output
1 Incorrect 424 ms 7252 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 8532 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 8788 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 11604 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 8616 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 8784 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 8788 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 8772 KB Wrong Answer.
2 Halted 0 ms 0 KB -