제출 #1159886

#제출 시각아이디문제언어결과실행 시간메모리
1159886salmonJanjetina (COCI21_janjetina)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

int N;
bool visited[100100];
vector<int> v[100100];
vector<pair<int,int>> adjlst[100100];
int u,v,w;
int sise[100100];
int le[100100];

void dfs(int i, int p, int de){
    sise[i] = 1;
    le[de] = 0;

    for(pair<int,int> ii : adjlst[i]){
        if(visited[ii.first] || ii.first == p) continue;
        dfs(ii.first,i,de+1);
        sise[i] += sise[ii.first];
    }
}

void digfs(int i, int p, int vi, int de, int bog){
    le[de]++;


    for(pair<int,int> ii : adjlst[i]){
        if(visited[ii.first] || ii.first == p) continue;
        digfs(ii.first,i,vi,de+1);
        sise[i] += sise[ii.first];
    }
}

long long decomp(int i){
    dfs(i,-1);

    int n = sise[i];
    int c = i;

    while(true){
        int temp = c;
        for(pair<int,int> ii : adjlst[c]){
            if(visited[ii.first] || ii.first == p) continue;
            if(sise[ii.first] >= n/2){
                c = ii.first;
                break;
            }
        }
        if(temp == c) break;
    }

    le[0]++;

    int cont = 0;
    vector<vector<pair<int,int> >> v;
    for(pair<int,int> ii : adjlst[c]){
        if(visited[ii.first]) continue;
        digfs(ii.first,c,1,cont);
        cont++;
    }


}

int main(){

    scanf(" %d",&N);
    scanf(" %d",&K);

    for(int i = 0; i < N - 1; i++){
        scanf(" %d",&u);
        scanf(" %d",&v);
        scanf(" %d",&w);
        w -= k;
        adjlst[u].push_back({v,w});
        adjlst[v].push_back({u,w});
    }

    for(int i = 1; i <= N; i++) visited[i] = false;

    decomp(1);
}

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

Main.cpp:8:7: error: conflicting declaration 'int v'
    8 | int u,v,w;
      |       ^
Main.cpp:6:13: note: previous declaration as 'std::vector<int> v [100100]'
    6 | vector<int> v[100100];
      |             ^
Main.cpp: In function 'void digfs(int, int, int, int, int)':
Main.cpp:29:14: error: too few arguments to function 'void digfs(int, int, int, int, int)'
   29 |         digfs(ii.first,i,vi,de+1);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:23:6: note: declared here
   23 | void digfs(int i, int p, int vi, int de, int bog){
      |      ^~~~~
Main.cpp: In function 'long long int decomp(int)':
Main.cpp:35:8: error: too few arguments to function 'void dfs(int, int, int)'
   35 |     dfs(i,-1);
      |     ~~~^~~~~~
Main.cpp:12:6: note: declared here
   12 | void dfs(int i, int p, int de){
      |      ^~~
Main.cpp:43:49: error: 'p' was not declared in this scope
   43 |             if(visited[ii.first] || ii.first == p) continue;
      |                                                 ^
Main.cpp:58:14: error: too few arguments to function 'void digfs(int, int, int, int, int)'
   58 |         digfs(ii.first,c,1,cont);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:23:6: note: declared here
   23 | void digfs(int i, int p, int vi, int de, int bog){
      |      ^~~~~
Main.cpp:63:1: warning: no return statement in function returning non-void [-Wreturn-type]
   63 | }
      | ^
Main.cpp: In function 'int main()':
Main.cpp:68:18: error: 'K' was not declared in this scope
   68 |     scanf(" %d",&K);
      |                  ^
Main.cpp:72:18: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'std::vector<int> (*)[100100]' [-Wformat=]
   72 |         scanf(" %d",&v);
      |                 ~^  ~~
      |                  |  |
      |                  |  std::vector<int> (*)[100100]
      |                  int*
Main.cpp:74:14: error: 'k' was not declared in this scope
   74 |         w -= k;
      |              ^
Main.cpp:75:28: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
   75 |         adjlst[u].push_back({v,w});
      |         ~~~~~~~~~~~~~~~~~~~^~~~~~~
In file included from /usr/include/c++/11/vector:67,
                 from /usr/include/c++/11/functional:62,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from Main.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<int, int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
Main.cpp:76:15: error: invalid types 'std::vector<std::pair<int, int> > [100100][std::vector<int> [100100]]' for array subscript
   76 |         adjlst[v].push_back({u,w});
      |               ^
Main.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |     scanf(" %d",&N);
      |     ~~~~~^~~~~~~~~~
Main.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         scanf(" %d",&u);
      |         ~~~~~^~~~~~~~~~
Main.cpp:72:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         scanf(" %d",&v);
      |         ~~~~~^~~~~~~~~~
Main.cpp:73:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         scanf(" %d",&w);
      |         ~~~~~^~~~~~~~~~