제출 #1360938

#제출 시각아이디문제언어결과실행 시간메모리
1360938eyadooz경주 (Race) (IOI11_race)C++20
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h>
#include "race.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define endl '\n'
int k, cn=0, sub[200005], ans=INT_MAX, pref[200005], depth[200005];
vector<int> adj[200005];
bool deleted[200005];
map<int, int> mn;
void dfs(int x, int p=-1) 
{
    cn++;
    sub[x]=1;
    for(auto[i, _] : adj[x]) 
    {
        if(!deleted[i]&&i!=p) {dfs(i, x);sub[x]+=sub[i];}
    }
}
int centr(int x, int p=-1) 
{
    for(auto[i, _] : adj[x]) 
    {
        if(i!=p&&!deleted[i]&&sub[i]>cn/2) return centr(i, x);
    }
    return x;
}
void init(int x, int p=-1) 
{
    for(auto[i, w] : adj[x]) 
    {
        if(i==p||deleted[i]) continue;
        pref[i]=pref[x]+w;
        depth[i]=depth[x]+1;
        init(i, x);
    }
}
void query(int x, int p=-1) 
{
    if(pref[x]==k) ans=min(ans, depth[x]);
    if(mn[k-pref[x]]!=NULL) ans=min(ans, mn[k-pref[x]]+depth[x]);
    for(auto[i, _]:adj[x]) 
    {
        if(i!=p&&!deleted[i]) query(i, x);
    }
}
void update(int x, int p=-1) 
{
    mn[pref[x]]=min(mn[pref[x]], depth[x]);
    for(auto[i, _]:adj[x]) 
    {
        if(i!=p&&!deleted[i]) update(i, x);
    }
}
void solve(int x) 
{
    pref[x]=0;
    depth[x]=0;
    init(x);
    for(auto i : adj[x]) 
    {
        if(deleted[i]) continue;
        query(i);
        update(i);
    }
}
void decompose(int v) 
{
    cn=0;
    dfs(v);
    int cen=centr(v);
    solve(cen);
    deleted[cen]=1;
    for(auto i : adj[cen]) 
    {
        if(!deleted[i]) decompose(i);
    }
}
int best_path(int N, int K, int H[][2], int L[])
{
    k=K;
    for(int i = 0;i < N-1;i++) 
    {
        auto[x, y]=H[i];
        auto w=L[i];
        adj[x].pb({y, w});
        adj[y].pb({x, w});
    }
    decompose(1);
    return ans;
}
// int main()
// {
//     cin.tie(0) -> sync_with_stdio(0);

// }

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

race.cpp: In function 'void dfs(int, int)':
race.cpp:22:13: error: cannot decompose non-array non-class type 'int'
   22 |     for(auto[i, _] : adj[x])
      |             ^~~~~~
race.cpp: In function 'int centr(int, int)':
race.cpp:29:13: error: cannot decompose non-array non-class type 'int'
   29 |     for(auto[i, _] : adj[x])
      |             ^~~~~~
race.cpp: In function 'void init(int, int)':
race.cpp:37:13: error: cannot decompose non-array non-class type 'int'
   37 |     for(auto[i, w] : adj[x])
      |             ^~~~~~
race.cpp: In function 'void query(int, int)':
race.cpp:48:23: warning: NULL used in arithmetic [-Wpointer-arith]
   48 |     if(mn[k-pref[x]]!=NULL) ans=min(ans, mn[k-pref[x]]+depth[x]);
      |                       ^~~~
race.cpp:49:13: error: cannot decompose non-array non-class type 'int'
   49 |     for(auto[i, _]:adj[x])
      |             ^~~~~~
race.cpp: In function 'void update(int, int)':
race.cpp:57:13: error: cannot decompose non-array non-class type 'int'
   57 |     for(auto[i, _]:adj[x])
      |             ^~~~~~
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:93:18: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   93 |         adj[x].pb({y, w});
      |         ~~~~~~~~~^~~~~~~~
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53,
                 from race.cpp:1:
/usr/include/c++/13/bits/stl_vector.h:1281:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1281 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<int>::value_type&' {aka 'const int&'}
 1281 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:1298:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1298 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1298:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1298 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
race.cpp:94:18: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   94 |         adj[y].pb({x, w});
      |         ~~~~~~~~~^~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1281 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1281:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<int>::value_type&' {aka 'const int&'}
 1281 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:1298:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1298 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1298:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1298 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~