Submission #1009298

#TimeUsernameProblemLanguageResultExecution timeMemory
1009298pccCyberland (APIO23_cyberland)C++17
100 / 100
1976 ms11652 KiB
#include "cyberland.h"

#include <vector>
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")
using namespace std;
#define ld double
#define pii pair<int,int>
#define fs first
#define sc second
#define mt make_tuple

const ld inf = 1e15;
const int mxn  = 2e5+10;
const int lim = 70;
ld dist[mxn];
int head[mxn*2],nid[mxn*2],to[mxn*2],wei[mxn*2];
int ptr = 0;
bitset<mxn> able;
int N,M;

void add_edge(int a,int b,int c){
	ptr++;
	nid[ptr] = head[a];
	head[a] = ptr;
	to[ptr] = b;
	wei[ptr] = c;
	return;
}

namespace DIJKSTRA{
	bitset<mxn> done;
	priority_queue<pair<ld,int>,vector<pair<ld,int>>,greater<pair<ld,int>>> pq;
	void GO(int ban){
		for(int i = 0;i<N;i++){
			dist[i+N] = inf;
			done[i] = done[i+N] = false;
			if(ban != i&&able[i]){
				pq.push(make_pair(dist[i],i));
			}
		}
		while(!pq.empty()){
			auto now = pq.top().sc;
			pq.pop();
			if(done[now])continue;
			done[now] = true;
			int pid = (now<N?now:now-N);
			for(int eid = head[pid];eid;eid = nid[eid]){
				int w = wei[eid],nxt = to[eid];
				if(!able[nxt]||done[nxt+N])continue;
				if(dist[nxt+N] > dist[now]+w){
					dist[nxt+N] = dist[now]+w;
					if(nxt != ban)pq.push(make_pair(dist[nxt+N],nxt+N));
				}
			}
		}
		return;
	}
}

void init(){
	fill(head,head+N,0);
	ptr = 0;
}

double solve(int NN, int MM, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> z, std::vector<int> arr) {
	init();
	N = NN,M = MM;
	for(int i = 0;i<M;i++){
		int a = x[i],b = y[i],c = z[i];
		add_edge(a,b,c);
		add_edge(b,a,c);
	}
	for(int i = 0;i<N*2;i++)able[i] = true;
	for(int i = 0;i<N;i++)dist[i] = inf;
	dist[0] = 0;
	DIJKSTRA::GO(H);
	for(int i = 0;i<N;i++){
		able[i] = able[i+N] = (min(dist[i],dist[i+N])+1<inf);
	}
	for(int i = 0;i<N;i++){
		if(able[i]&&arr[i] == 0)dist[i] = 0;
		else dist[i] = inf;
	}
	if(!able[H])return -1;
	dist[0] = 0;
	ld ans = inf;
	for(int i = 0;i<=min(K,lim);i++){
		DIJKSTRA::GO(H);
		ans = min({ans,dist[H],dist[H+N]});
		if(i+1<=min(K,lim)&&arr[H] == 2)ans = min({ans,dist[H+N]/2});
		for(int j = 0;j<N;j++){
			dist[j] = min(dist[j],dist[j+N]);
			if(able[j]&&arr[j] == 2)dist[j] = min(dist[j],dist[j+N]/2);
		}
		dist[H] = inf;
	}
	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...