Submission #1061041

# Submission time Handle Problem Language Result Execution time Memory
1061041 2024-08-16T05:50:57 Z Halym2007 Cyberland (APIO23_cyberland) C++17
49 / 100
29 ms 15196 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 <ll, ll>
const int N = 2e5 + 5;
 
vector <pii> v[N];
ll dis[N];
priority_queue <pair <ll, ll>, vector<pair <ll, ll>>, greater <pair <ll, ll>>> q;
ll n, m, k, h, vis[N];
vector <ll> a, tt;
double jogap = 1e16;
void dfs (ll x) {
	vis[x] = 1;
	if (a[x] == 0) {
		tt.pb (x);
	}
	for (pii i : v[x]) {
		if (vis[i.ff]) continue;
		dfs(i.ff);
	}
}

void dfs1(int x, int par, double val) {
	if (x == h) {
		jogap = min (jogap, val);
		return;
	}
	for (pii i : v[x]) {
		if (i.ff == par or i.ff == 0) {
			continue;
		}
		double new_val = val + i.ss;
		if (!a[i.ff]) new_val = 0;
		else if (a[i.ff] == 2 and k != 0) new_val /= 2.0;
		dfs1 (i.ff, x, new_val);
	}
}
 
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;
	a.resize(n);
	for (int i = 0; i < n; ++i) {
		a[i] = arr[i];
	}
	for (int i = 0; i < m; ++i) {
		v[x[i]].pb ({y[i], c[i]});
		v[y[i]].pb ({x[i], c[i]});
	}
	if (n <= 3) {
		jogap = 1e16;
		dfs1(0, -1, 0);
		if (jogap == 1e16) jogap = -1;
		for (int i = 0; i < n; ++i) {
			v[i].clear();
		}
		return jogap;
	} 
	
	for (ll i = 0; i < n; ++i) {
		dis[i] = 1e16;
	}
	q.push ({0, h});
	dis[h] = 0;
	while (!q.empty()) {
		ll 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});
			}		
		}
	} 
	jogap = 1e16;
	jogap = min (jogap, (double)dis[0]);
	vis[h] = 1;
	dfs (0);
	
	for (ll i : tt) {
		jogap = min (jogap, (double)dis[i]);
	}
	
	if (jogap == (double)1e16) jogap = -1;
	for (ll i = 0; i < n; ++i) {
		v[i].clear();
		vis[i] = 0;
	}
	tt.clear();
	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 Correct 12 ms 8024 KB Correct.
2 Correct 12 ms 8540 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8280 KB Correct.
2 Correct 17 ms 8312 KB Correct.
3 Correct 16 ms 8284 KB Correct.
4 Correct 26 ms 8280 KB Correct.
5 Correct 16 ms 8284 KB Correct.
6 Correct 15 ms 9012 KB Correct.
7 Correct 21 ms 9052 KB Correct.
8 Correct 10 ms 9940 KB Correct.
9 Correct 17 ms 8028 KB Correct.
10 Correct 15 ms 9048 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 17 ms 8284 KB Correct.
2 Correct 18 ms 8264 KB Correct.
3 Correct 19 ms 9052 KB Correct.
4 Correct 18 ms 9052 KB Correct.
5 Correct 19 ms 9048 KB Correct.
6 Correct 6 ms 9136 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 13916 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8284 KB Correct.
2 Correct 17 ms 9308 KB Correct.
3 Correct 18 ms 9276 KB Correct.
4 Correct 19 ms 10588 KB Correct.
5 Correct 15 ms 8796 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 21 ms 8284 KB Correct.
2 Correct 14 ms 8432 KB Correct.
3 Correct 29 ms 15196 KB Correct.
4 Correct 12 ms 9308 KB Correct.
5 Correct 15 ms 8028 KB Correct.
6 Correct 17 ms 9308 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 8284 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 8284 KB Wrong Answer.
2 Halted 0 ms 0 KB -