Submission #881642

# Submission time Handle Problem Language Result Execution time Memory
881642 2023-12-01T16:37:18 Z tsumondai Cyberland (APIO23_cyberland) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "cyberland.h"
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME  (1.0 * clock() / CLOCKS_PER_SEC)

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
typedef pair<double, int> ar;

const int N = 1e5 + 5;

const int oo = 1e9, mod = 1e9 + 7;
int n, m, h;
double ans = 0;
bool vis[N];
double dis[N], dis2[N];
vector<ii> adj[N];
priority_queue<ar, vector<ar>, greater<ar>> pq;

void dijkstra(){
	fill(vis,vis+n+1,0);
	for(int i = 0; i < n; i++) 
		if(dis[i]<oo) pq.push({dis[i],i});
	while(!pq.empty()){
		auto tmp = pq.top(); pq.pop(); 
		double D=tmp.fi; int a=tmp.se;
		if(vis[a] || a==h) continue; vis[a]=1;
		for(auto tmp : adj[a]) {
			int b=tmp.fi, w=tmp.se;
			if(dis[b]>dis[a]+w) 
			dis[b]=dis[a]+w, pq.push({dis[b],b});
		}
	}
	ans = min(ans, dis[h]);
}

double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> A) {
	n = N, m = M, h = H, K = min(K, 67ll);
	fill(dis, dis + n, oo); ans = oo;
	for (int i = 0; i < n; i++) adj[i].clear();
	for (int i = 0; i < m; i++)
		adj[x[i]].push_back({y[i], c[i]}),
		    adj[y[i]].push_back({x[i], c[i]});
	dis[0] = 0; dijkstra(); if (dis[h] >= oo) return -1;
	for (int i = 0; i < n; i++)
		if (dis[i] != oo) dis[i] = A[i] && i ? oo : 0;
	for (int i = 0; i <= K; i++) {
		dijkstra(); fill(dis2, dis2 + n, oo);
		for (int j = 0; j < n; j++)
			if (A[j] > 1) for (auto tmp : adj[j]) {
				int u=tmp.fi, w=tmp.se;
				dis2[u] = min(dis2[u], dis[j] / 2 + w);
			}		
		for (int j = 0; j < n; j++) dis[j] = dis2[j];
	}
	return ans;
}


/*
Xét các trường hợp đặc biệt
Kiểm tra lại input/output
Cố gắng trâu
Lật ngược bài toán
Keep calm and get VOI
Flow:

*/

Compilation message

cyberland.cpp: In function 'void dijkstra()':
cyberland.cpp:36:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   36 |   if(vis[a] || a==h) continue; vis[a]=1;
      |   ^~
cyberland.cpp:36:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   36 |   if(vis[a] || a==h) continue; vis[a]=1;
      |                                ^~~
cyberland.cpp:35:10: warning: unused variable 'D' [-Wunused-variable]
   35 |   double D=tmp.fi; int a=tmp.se;
      |          ^
/usr/bin/ld: /tmp/ccimzkle.o: in function `main':
grader.cpp:(.text.startup+0x696): undefined reference to `solve(int, int, int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status