제출 #1296234

#제출 시각아이디문제언어결과실행 시간메모리
1296234eri16기지국 (IOI20_stations)C++20
컴파일 에러
0 ms0 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; vector<int> label(int n, int k, vector<int> u, vector<int> v) { vector<vector<int>> adj(n+1); for(int i=0;i<n-1;i++){ adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); } vector<int> lbl(n); int ans=0; for (int i=0; i<n; i++){ if (adj[u].size()>2){ans=i;} } queue <pair<int,pair<int,int>>> q; int visited[n]=0; visited[ans]=1; lbl[ans]=0; for (int i=0; i<adj[ans].size(); i++){ q.push({adj[ans][i],{i+1,1}}); } while (q.size()){ auto x = q.front(); q.pop(); int node=x.first; int depth=x.second.second; int color=x.second.first; if (visited[node]==0){ visited[node]=1; lbl[node]=color*1000+depth; for (int i=0; i<adj[node].size(); i++){ q.push({adj[node][i],{color,depth+1}}); } } } return lbl; } int find_next_station(int s, int t, vector <int> cp){ if (s==0){ for (int i=0; i<cp.size(); i++){ if (cp[i]/1000=t/1000){return cp[i];} } } else if(s/1000!=t/1000){ return cp[0]; } else{ if(t<s){ return c[0]; } else{ return c[1]; } } }

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

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:19:16: error: no match for 'operator[]' (operand types are 'std::vector<std::vector<int> >' and 'std::vector<int>')
   19 |         if (adj[u].size()>2){ans=i;}
      |                ^
In file included from /usr/include/c++/13/vector:66,
                 from stations.h:1,
                 from stations.cpp:1:
/usr/include/c++/13/bits/stl_vector.h:1126:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; reference = std::vector<int>&; size_type = long unsigned int]'
 1126 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1126:28: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'}
 1126 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:1145:7: note: candidate: 'constexpr std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](size_type) const [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; const_reference = const std::vector<int>&; size_type = long unsigned int]'
 1145 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1145:28: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'}
 1145 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
stations.cpp:24:20: error: array must be initialized with a brace-enclosed initializer
   24 |     int visited[n]=0;
      |                    ^
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:60:22: error: lvalue required as left operand of assignment
   60 |             if (cp[i]/1000=t/1000){return cp[i];}
stations.cpp:70:20: error: 'c' was not declared in this scope
   70 |             return c[0];
      |                    ^
stations.cpp:73:20: error: 'c' was not declared in this scope
   73 |             return c[1];
      |                    ^