Submission #321797

# Submission time Handle Problem Language Result Execution time Memory
321797 2020-11-13T11:47:01 Z wind_reaper City Mapping (NOI18_citymapping) C++17
Compilation error
0 ms 0 KB
#include "citymapping.h"
#include <bits/stdc++.h>

using namespace std;
struct DSU{
	vector<int> e;
	void init(int n){
		e = vector<int>(n, -1);
	}

	int get(int x){
		return (e[x] < 0 ? x : e[x] = get(e[x]));
	}

	bool same_set(int x, int y){
		return get(x) == get(y);
	}

	bool unite(int x, int y){
		x = get(x), y = get(y);
		if(e[x] < e[y])
			swap(x, y);

		e[x] += e[y];
		e[y] = x;
		return true;
	}
};
void find_roads(int N, int Q, int A[], int B[], int W[]) {
	vector<pair<pair<int, int>, long long>> edges((N*(N-1))/2);
	int c = 0; 
	for(int i = 1; i <= N; i++)
		for(int j = i+1; j <= N; j++)
			edges[c++] = {{i, j}, get_distance(i, j)};

	sort(edges.begin(), edges.end(), [&](pair<pair<int, int>, long long> &a, pair<pair<int, int>, long long> &b){
		if(a.second < b.second) return true;
		return false;
	});

	DSU s;
	s.init(N);
	int m = 0;
	vector<int> c(N);
	for(int i = 0; i < c; i++){
		if(s.same_set(edges[i].first.first, edges[i].first.second) || c[edges[i].first.first] >= 3 || c[edges[i].second.second] >= 3) continue;
		s.unite(edges[i].first.first, edges[i].first.second);
		A[m] = edges[i].first.first, B[m] = edges[i].first.second, W[m] = edges[i].second;
		c[A[m]]++, c[B[m]]++;
		m++; 
	}
	return;
}

Compilation message

citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:44:14: error: conflicting declaration 'std::vector<int> c'
   44 |  vector<int> c(N);
      |              ^
citymapping.cpp:31:6: note: previous declaration as 'int c'
   31 |  int c = 0;
      |      ^
citymapping.cpp:46:87: error: invalid types 'int[int]' for array subscript
   46 |   if(s.same_set(edges[i].first.first, edges[i].first.second) || c[edges[i].first.first] >= 3 || c[edges[i].second.second] >= 3) continue;
      |                                                                                       ^
citymapping.cpp:46:115: error: request for member 'second' in 'edges.std::vector<std::pair<std::pair<int, int>, long long int> >::operator[](((std::vector<std::pair<std::pair<int, int>, long long int> >::size_type)i)).std::pair<std::pair<int, int>, long long int>::second', which is of non-class type 'long long int'
   46 |   if(s.same_set(edges[i].first.first, edges[i].first.second) || c[edges[i].first.first] >= 3 || c[edges[i].second.second] >= 3) continue;
      |                                                                                                                   ^~~~~~
citymapping.cpp:49:9: error: invalid types 'int[int]' for array subscript
   49 |   c[A[m]]++, c[B[m]]++;
      |         ^
citymapping.cpp:49:20: error: invalid types 'int[int]' for array subscript
   49 |   c[A[m]]++, c[B[m]]++;
      |                    ^