Submission #840957

# Submission time Handle Problem Language Result Execution time Memory
840957 2023-09-01T02:20:36 Z GoldLight Cyberland (APIO23_cyberland) C++17
8 / 100
946 ms 2097152 KB
#include <bits/stdc++.h>
using namespace std;
void fast(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}

const int N=1e5;
const double INF=1e16;
int n, m, k, h;
vector<pair<int,int>> v[N+1], ad; //adventure graph
vector<int> a;
bool f=false; //find cyberland
void dfs(int node, int p){
	if(f) return;
	for(auto [i, d]:v[node]){
		if(i==p) continue;
		int di=0;
		if(a[i]!=0) di=d;
		ad.push_back({di, a[i]});
		if(i==h) f=true;
		dfs(i, node);
	}
	if(f) return;
	ad.pop_back();
}
priority_queue<tuple<double,int,int>, vector<tuple<double,int,int>>, greater<tuple<double,int,int>>> pq;
double solve(int nn, int mm, int kk, int hh, vector<int> x, vector<int> y, vector<int> c, vector<int> aa){
	for(int i=0; i<n; i++) v[i].clear();
	n=nn, m=mm, k=kk, h=hh, a=aa;
	for(int i=0; i<m; i++){
		v[x[i]].push_back({y[i], c[i]});
		v[y[i]].push_back({x[i], c[i]});
	}
	// if(m==n-1){
	// 	ad.clear();
	// 	dfs(0, -1);
	// 	priority_queue<int> pqq;
	// 	double ans=0;
	// 	for(auto [p, q]:ad){
	// 		if(q==2) pqq.push(p);
	// 		else ans+=p;
	// 	}
	// 	while(!pqq.empty()){
	// 		int u=pqq.top(); pqq.pop();
	// 		if(k) ans+=double(u)/2;
	// 		else ans+=u;
	// 		k--;
	// 	}
	// 	return ans;
	// }
	vector<vector<double>> dp(n+1, vector<double>(k+1, INF));
	dp[0][0]=0;
	pq.push({0, 0, 0}); //not yet disc
	while(!pq.empty()){
		auto[d, u, dis]=pq.top(); pq.pop();
		for(auto [to, dist]:v[u]){
			if(a[to]==0){
				if(0<dp[to][dis]){
					dp[to][dis]=0;
					pq.push({0, to, dis});
				}
			}
			else if(a[to]==1){
				if(dp[u][dis]+dist<dp[to][dis]){
					dp[to][dis]=dp[u][dis]+dist;
					pq.push({dp[to][dis], to, dis});
				}
			}
			else{
				if(dp[u][dis]+dist<dp[to][dis]){
					dp[to][dis]=dp[u][dis]+dist;
					pq.push({dp[to][dis], to, dis});
				}
				if(dis<k && (dp[u][dis]+dist)/2<dp[to][dis+1]){
					dp[to][dis+1]=(dp[u][dis]+dist)/2;
					pq.push({dp[to][dis+1], to, dis+1});
				}
			}
		}
	}
	double ans=INF;
	for(int i=0; i<=k; i++) ans=min(ans, dp[h][i]);
	return ans;
}
/*
int main(){
	fast();
	int n, m, k, h; cin>>n>>m>>k>>h;
	vector<int> x(N+1), y(N+1), c(N+1), a(N+1); 
	for(int i=0; i<m; i++){
		cin>>x[i]>>y[i]>>c[i];
	}
	for(int i=0; i<n; i++) cin>>a[i];
	cout<<solve(n, m, k, h, x, y, c, a);
}
*/
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 2772 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 3028 KB Correct.
2 Correct 22 ms 3028 KB Correct.
3 Correct 21 ms 3052 KB Correct.
4 Correct 22 ms 3028 KB Correct.
5 Correct 22 ms 3028 KB Correct.
6 Correct 20 ms 6040 KB Correct.
7 Correct 27 ms 5968 KB Correct.
8 Correct 14 ms 9428 KB Correct.
9 Correct 21 ms 2644 KB Correct.
10 Correct 21 ms 2772 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 3028 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 946 ms 22504 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 3112 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 3104 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 279 ms 3300 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 636 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -