Submission #983867

# Submission time Handle Problem Language Result Execution time Memory
983867 2024-05-16T07:32:49 Z Halym2007 Cyberland (APIO23_cyberland) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "cyberland.h"
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define sz size()
#define ll long long
const int N = 1e5 + 5;
 
vector <pair <int, ll>> v[N];
 
ll dis[N];
bool vis[N];
 
void dfs (int x) {
	vis[x] = 1;
	for (pii i : v[x]) {
		if (vis[i.ff]) continue;
		dfs (i.ff);
	}
}
 
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
 	for (int i = 0; i < M; ++i) {
// 		cout << i << " --> " << x[i] << " " << y[i];
		v[x[i]].pb ({y[i], (ll)c[i]});
		v[y[i]].pb ({x[i], (ll)c[i]});
	}
	for (int i = 0; i < N; ++i) {
		dis[i] = 1e18;
	}
	vis[H] = 1;
	dfs (0);
	vis[H] = 0;
	
	priority_queue <pair <ll, int>, vector <pair <ll, int>>, greater <pair <ll, int>>> q;
	
	q.push ({0, H});
	dis[H] = 0;
	while (!q.empty()) {
		int x = q.top().ss;
		q.pop();
		for (pair <int, ll> 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});
			}
		}
	}
//	for (int i = 0; i < N; ++i) {
//		cout << i << " -- > " << dis[i] << " " << vis[i] << "\n";
//	}
//	exit(0);
	double jogap;
	if (dis[0] != 1e18) {
		jogap = dis[0];
		for (int i = 0; i < N; ++i) {
			if (!i or (!arr[i] and vis[i])) {
				if (jogap == -1) {
					jogap = (double)dis[i];
				}
				else jogap = min (jogap, (double)dis[i]);
			}
		}
	}
	else {
		jogap = -1;
	}
	for (int i = 0; i < N; ++i) {
		v[i].clear();
		vis[i] = 0;
	}
	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));
//	}
//}

Compilation message

cyberland.cpp: In function 'void dfs(int)':
cyberland.cpp:18:7: error: 'pii' was not declared in this scope
   18 |  for (pii i : v[x]) {
      |       ^~~
cyberland.cpp:22:1: error: expected primary-expression before '}' token
   22 | }
      | ^
cyberland.cpp:21:3: error: expected ';' before '}' token
   21 |  }
      |   ^
      |   ;
   22 | }
      | ~  
cyberland.cpp:22:1: error: expected primary-expression before '}' token
   22 | }
      | ^
cyberland.cpp:21:3: error: expected ')' before '}' token
   21 |  }
      |   ^
      |   )
   22 | }
      | ~  
cyberland.cpp:18:6: note: to match this '('
   18 |  for (pii i : v[x]) {
      |      ^
cyberland.cpp:22:1: error: expected primary-expression before '}' token
   22 | }
      | ^