답안 #639875

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
639875 2022-09-12T15:15:52 Z Stavab 악어의 지하 도시 (IOI11_crocodile) C++14
컴파일 오류
0 ms 0 KB
#include "crocodile.h"
#include <iostream>
#include <vector>
#include <utility>
#include <set>

using namespace std;

#define INF 9999999999

vector<vector<pair<int, int>>> tree;
vector<long long> times;
vector<int> visited;

void dfs(int n)
{
    if(visited[n])
        return;
    else
        visited[n] = 1;
        
    set<long long> s;
    for(int i = 0; i < tree[n].size(); i++)
    {
        dfs(tree[n][i].first);
        s.insert(times[tree[n][i].first] + tree[n][i].second);
    }
    
    if(*(++s.begin()) >= INF)
        times[n] = INF;
    else
        times[n] = *(++s.begin());
}

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
    tree.assign(N, vector<int>())
    
    for(int i = 0; i < N - 1; i++)
    {
        tree[R[i][0]].push_back(make_pair(R[i][1], L[i]));
        tree[R[i][1]].push_back(make_pair(R[i][0], L[i]));
    }
    
    for(int i = 0; i < N; i++)
        times[i] = INF;
        
    for(int i = 0; i < K; i++)
        times[P[i]] = 0;
        
    dfs(0);
        
    return (int)times[0];
}

Compilation message

crocodile.cpp: In function 'void dfs(int)':
crocodile.cpp:23:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i = 0; i < tree[n].size(); i++)
      |                    ~~^~~~~~~~~~~~~~~~
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:37:33: error: no matching function for call to 'std::vector<std::vector<std::pair<int, int> > >::assign(int&, std::vector<int>)'
   37 |     tree.assign(N, vector<int>())
      |                                 ^
In file included from /usr/include/c++/10/vector:67,
                 from crocodile.cpp:3:
/usr/include/c++/10/bits/stl_vector.h:749:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = std::vector<std::pair<int, int> >; _Alloc = std::allocator<std::vector<std::pair<int, int> > >; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = std::vector<std::pair<int, int> >]'
  749 |       assign(size_type __n, const value_type& __val)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:749:47: note:   no known conversion for argument 2 from 'std::vector<int>' to 'const value_type&' {aka 'const std::vector<std::pair<int, int> >&'}
  749 |       assign(size_type __n, const value_type& __val)
      |                             ~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/10/bits/stl_vector.h:768:2: note: candidate: 'template<class _InputIterator, class> void std::vector<_Tp, _Alloc>::assign(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; <template-parameter-2-2> = <template-parameter-1-2>; _Tp = std::vector<std::pair<int, int> >; _Alloc = std::allocator<std::vector<std::pair<int, int> > >]'
  768 |  assign(_InputIterator __first, _InputIterator __last)
      |  ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:768:2: note:   template argument deduction/substitution failed:
crocodile.cpp:37:33: note:   deduced conflicting types for parameter '_InputIterator' ('int' and 'std::vector<int>')
   37 |     tree.assign(N, vector<int>())
      |                                 ^
In file included from /usr/include/c++/10/vector:67,
                 from crocodile.cpp:3:
/usr/include/c++/10/bits/stl_vector.h:794:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(std::initializer_list<_Tp>) [with _Tp = std::vector<std::pair<int, int> >; _Alloc = std::allocator<std::vector<std::pair<int, int> > >]'
  794 |       assign(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:794:7: note:   candidate expects 1 argument, 2 provided
crocodile.cpp:39:20: error: 'i' was not declared in this scope
   39 |     for(int i = 0; i < N - 1; i++)
      |                    ^