제출 #772057

#제출 시각아이디문제언어결과실행 시간메모리
772057Essa2006공장들 (JOI14_factories)C++14
컴파일 에러
0 ms0 KiB
#include "factories.h" #include<bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' #define FF first #define SS second #define all(a) a.begin(), a.end() #define mod (ll)(1000000007) // #define MAX_N 500000 // #define MAX_Q 100000 // #define MAX_SUM_ST 1000000 // #define MAX_VALUE 1000000000 // static int N, Q; // static int A[MAX_N], B[MAX_N], D[MAX_N]; // static int S[MAX_N]; // static int T[MAX_N]; // static int X[MAX_SUM_ST]; // static int Y[MAX_SUM_ST]; // static int Qx[MAX_N]; // static int Qy[MAX_N]; const ll inf=1e15, lg=19; int n; vector<ll>Dis; vector<int>dpth vector<vector<int>>AA, up; vector<vector<int>>Lca; map<pair<int, int>, ll>mp; void pre(){ //Dis.clear(), dpth.clear(), AA.clear(), up.clear(), Lca.clear(), mp.clear(); Dis.resize(n, inf), dpth.resize(n, 2*n), AA.resize(n), up.resize(n, vector<int>(lg+1)), Lca.resize(n, vector<ll>(lg+1)); } void bfs(int ind){ queue<int>q; q.push(ind); up[ind][0]=ind, Lca[ind][0]=0; Dis[ind]=dpth[ind]=0; while(!q.empty()){ int u=q.front(); q.pop(); for(int j=1;j<=lg;j++){ up[u][j]=up[up[u][j-1]][j-1]; Lca[u][j]=min(inf, Lca[u][j-1]+Lca[up[u][j-1]][j-1]); } for(int i=0;i<AA[u].size();i++){ int v=AA[u][i]; if(dpth[u]+1<dpth[v]){ dpth[v]=dpth[u]+1, Dis[v]=Dis[u]+mp[{u, v}]; up[v][0]=u, Lca[v][0]=mp[{u, v}]; q.push(v); } } } } ll get_dis(int u, int v){ // u // v ll res=0; if(dpth[u]>dpth[v]) swap(u, v); for(int j=lg;j>=0;j--){ if(dpth[up[v][j]]>dpth[u]) res+=Lca[v][j], v=up[v][j]; } if(dpth[u]!=dpth[v]) res+=Lca[v][0], v=up[v][0]; if(u==v) return res; for(int j=lg;j>=0;j--){ if(up[u][j]!=up[v][j]) res+=Lca[u][j]+Lca[v][j], u=up[u][j], v=up[v][j]; } res+=Lca[u][0]+Lca[v][0]; return res; } void Init(int N, int A[], int B[], int D[]) { n=N; pre(); for(int i=0;i<n-1;i++){ int u=A[i], v=B[i], w=D[i]; AA[u].push_back(v); AA[v].push_back(u); mp[{u, v}]=mp[{v, u}]=w; } bfs(0); } long long Query(int S, int X[], int T, int Y[]) { ll ans=inf; for(int i=0;i<S;i++){ for(int j=0;j<T;j++){ ans=min(ans, get_dis(X[i], Y[j])); } } return ans; }

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

factories.cpp:28:1: error: expected initializer before 'vector'
   28 | vector<vector<int>>AA, up;
      | ^~~~~~
factories.cpp: In function 'void pre()':
factories.cpp:34:25: error: 'dpth' was not declared in this scope
   34 |     Dis.resize(n, inf), dpth.resize(n, 2*n), AA.resize(n), up.resize(n, vector<int>(lg+1)), Lca.resize(n, vector<ll>(lg+1));
      |                         ^~~~
factories.cpp:34:46: error: 'AA' was not declared in this scope
   34 |     Dis.resize(n, inf), dpth.resize(n, 2*n), AA.resize(n), up.resize(n, vector<int>(lg+1)), Lca.resize(n, vector<ll>(lg+1));
      |                                              ^~
factories.cpp:34:60: error: 'up' was not declared in this scope; did you mean 'mp'?
   34 |     Dis.resize(n, inf), dpth.resize(n, 2*n), AA.resize(n), up.resize(n, vector<int>(lg+1)), Lca.resize(n, vector<ll>(lg+1));
      |                                                            ^~
      |                                                            mp
factories.cpp:34:123: error: no matching function for call to 'std::vector<std::vector<int> >::resize(int&, std::vector<long long int>)'
   34 |     Dis.resize(n, inf), dpth.resize(n, 2*n), AA.resize(n), up.resize(n, vector<int>(lg+1)), Lca.resize(n, vector<ll>(lg+1));
      |                                                                                                                           ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from factories.cpp:2:
/usr/include/c++/10/bits/stl_vector.h:937:7: note: candidate: 'void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
  937 |       resize(size_type __new_size)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:937:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/10/bits/stl_vector.h:957:7: note: candidate: 'void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = std::vector<int>]'
  957 |       resize(size_type __new_size, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:957:54: note:   no known conversion for argument 2 from 'std::vector<long long int>' to 'const value_type&' {aka 'const std::vector<int>&'}
  957 |       resize(size_type __new_size, const value_type& __x)
      |                                    ~~~~~~~~~~~~~~~~~~^~~
factories.cpp: In function 'void bfs(int)':
factories.cpp:40:5: error: 'up' was not declared in this scope; did you mean 'mp'?
   40 |     up[ind][0]=ind, Lca[ind][0]=0;
      |     ^~
      |     mp
factories.cpp:41:14: error: 'dpth' was not declared in this scope
   41 |     Dis[ind]=dpth[ind]=0;
      |              ^~~~
factories.cpp:49:23: error: 'AA' was not declared in this scope
   49 |         for(int i=0;i<AA[u].size();i++){
      |                       ^~
factories.cpp: In function 'long long int get_dis(int, int)':
factories.cpp:64:8: error: 'dpth' was not declared in this scope
   64 |     if(dpth[u]>dpth[v])
      |        ^~~~
factories.cpp:67:12: error: 'dpth' was not declared in this scope
   67 |         if(dpth[up[v][j]]>dpth[u])
      |            ^~~~
factories.cpp:67:17: error: 'up' was not declared in this scope; did you mean 'u'?
   67 |         if(dpth[up[v][j]]>dpth[u])
      |                 ^~
      |                 u
factories.cpp:70:8: error: 'dpth' was not declared in this scope
   70 |     if(dpth[u]!=dpth[v])
      |        ^~~~
factories.cpp:71:27: error: 'up' was not declared in this scope; did you mean 'u'?
   71 |         res+=Lca[v][0], v=up[v][0];
      |                           ^~
      |                           u
factories.cpp:75:12: error: 'up' was not declared in this scope; did you mean 'u'?
   75 |         if(up[u][j]!=up[v][j])
      |            ^~
      |            u
factories.cpp: In function 'void Init(int, int*, int*, int*)':
factories.cpp:86:9: error: 'AA' was not declared in this scope; did you mean 'A'?
   86 |         AA[u].push_back(v);
      |         ^~
      |         A