제출 #677602

#제출 시각아이디문제언어결과실행 시간메모리
677602YENGOYAN도로 폐쇄 (APIO21_roads)C++17
컴파일 에러
0 ms0 KiB
#include "roads.h"
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_map>
#include <cmath>
#include <climits>
#include <algorithm>
#include <random>
#include <queue>
#include <deque>
#include <iomanip>
#include <string>
#include <tuple>
#include <bitset>
#include <chrono>
#include <ctime>
#include <fstream>
#include <stack>
#include <cstdio>
using namespace std;
using ll = long long;

vector<vector<pair<int, int>>> gp;
vector<vector<vector<ll>>> dp;

void dfs(int u, int p, int k) {
	vector<ll> vec;
	for (pair<int, int>& v : gp[u]) {
		if (v.first == p) continue;
		dfs(v.first, u, k);
		dp[u][0][k] += dp[v.first][k][k];
		vec.push_back(dp[v.first][k - 1][k] + v.second - dp[v][k][k]);
	}	
	sort(vec.rbegin(), vec.rend());
	for (int i = 1; i <= k; ++i) {
		dp[u][i][k] = dp[u][i - 1][k];
		if (i - 1 < vec.size()) dp[u][i][k] += vec[i - 1];
	}
}


vector<ll> minimum_closure_costs(int n, vector<int> U,vector<int> V,vector<int> W) {
	gp = vector<vector<pair<int, int>>>(n);
	dp = vector<vector<vector<ll>>>(n, vector<vector<ll>>(n, vector<ll> (n)));
	ll sm = 0;
	for (int i = 0; i < U.size(); ++i) {
		gp[U[i]].push_back({ V[i], W[i] });
		gp[V[i]].push_back({ U[i], W[i] });
		sm += W[i];
	}
	vector<ll> vec(n);
	vec[0] = sm;
	for (int i = 1; i < n; ++i) {
		dfs(0, -1, i);
		vec[i] = sm - dp[0][i][i];
	}
	return vec;
}

컴파일 시 표준 에러 (stderr) 메시지

roads.cpp: In function 'void dfs(int, int, int)':
roads.cpp:35:54: error: no match for 'operator[]' (operand types are 'std::vector<std::vector<std::vector<long long int> > >' and 'std::pair<int, int>')
   35 |   vec.push_back(dp[v.first][k - 1][k] + v.second - dp[v][k][k]);
      |                                                      ^
In file included from /usr/include/c++/10/vector:67,
                 from roads.h:1,
                 from roads.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1043:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = std::vector<std::vector<long long int> >; _Alloc = std::allocator<std::vector<std::vector<long long int> > >; std::vector<_Tp, _Alloc>::reference = std::vector<std::vector<long long int> >&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1043:28: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'std::vector<std::vector<std::vector<long long int> > >::size_type' {aka 'long unsigned int'}
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1061:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) const [with _Tp = std::vector<std::vector<long long int> >; _Alloc = std::allocator<std::vector<std::vector<long long int> > >; std::vector<_Tp, _Alloc>::const_reference = const std::vector<std::vector<long long int> >&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1061:28: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'std::vector<std::vector<std::vector<long long int> > >::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
roads.cpp:40:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   if (i - 1 < vec.size()) dp[u][i][k] += vec[i - 1];
      |       ~~~~~~^~~~~~~~~~~~
roads.cpp: In function 'std::vector<long long int> minimum_closure_costs(int, std::vector<int>, std::vector<int>, std::vector<int>)':
roads.cpp:49:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |  for (int i = 0; i < U.size(); ++i) {
      |                  ~~^~~~~~~~~~