제출 #831399

#제출 시각아이디문제언어결과실행 시간메모리
831399Trumling기지국 (IOI20_stations)C++14
컴파일 에러
0 ms0 KiB
#include "stations.h" #include <vector> #include<bits/stdc++.h> using namespace std; #define F first #define S second #define all(x) x.begin(),x.end() typedef long long ll; #define pb push_back #define INF 9999999999999999 ll nn; vector<vector<int>>g; ll here=0; vector<int>labels; void dfs(int i,int id,int start,int pre) { label[start]=i*nn + id; for(auto x:g[start]) if(pre!=x) dfs(i,id+1,x,start); } vector<int> label(int n, int k, vector<int> u, vector<int> v) { nn=n; g.assign(n,vector<int>()); labels.assign(n,0); vector<bool>cnt(n,0); for (int i = 0; i < n-1; i++) { g[u[i]].pb(v[i]); g[v[i]].pb(u[i]); if(g[u[i]].size()>2) here=u[i]; if(g[v[i]].size()>2) here=v[i]; if(g[u[i]].size()==2) cnt[u[i]]=1; if(g[v[i]].size()==2) cnt[v[i]]=1; } if(g[here].size()<=2) for(int i=0;i<n;i++) if(!cnt[i]) { here=i; break; } for(int i=0;i<g[here].size();i++) dfs(i,0,g[here][i],0) return labels; } int find_next_station(int s, int t, vector<int> c) { if(c.size()>2) { ll j=0; while(t-(j+nn)+1) j+=nn; return j; } ll mini=INF; for(auto x:c) mini=min(x,mini); if(t<s) return mini; ll j=0; while(t-(j+nn)+1) j+=nn; ll i=0; while(t-(i+nn)+1) i+=nn; if(i==j) return s+1; else return mini; }

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

stations.cpp: In function 'void dfs(int, int, int, int)':
stations.cpp:18:14: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   18 |   label[start]=i*nn + id;
      |              ^
stations.cpp:18:15: error: assignment of read-only location '*(label + ((sizetype)start))'
   18 |   label[start]=i*nn + id;
      |   ~~~~~~~~~~~~^~~~~~~~~~
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:56:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for(int i=0;i<g[here].size();i++)
      |               ~^~~~~~~~~~~~~~~
stations.cpp:57:25: error: expected ';' before 'return'
   57 |    dfs(i,0,g[here][i],0)
      |                         ^
      |                         ;
   58 | 
   59 |      return labels;
      |      ~~~~~~              
stations.cpp:60:5: warning: no return statement in function returning non-void [-Wreturn-type]
   60 |     }
      |     ^
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:75:18: error: no matching function for call to 'min(int&, ll&)'
   75 |   mini=min(x,mini);
      |                  ^
In file included from /usr/include/c++/10/vector:60,
                 from stations.h:1,
                 from stations.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
stations.cpp:75:18: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   75 |   mini=min(x,mini);
      |                  ^
In file included from /usr/include/c++/10/vector:60,
                 from stations.h:1,
                 from stations.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
stations.cpp:75:18: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   75 |   mini=min(x,mini);
      |                  ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from stations.cpp:3:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
stations.cpp:75:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   75 |   mini=min(x,mini);
      |                  ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from stations.cpp:3:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
stations.cpp:75:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   75 |   mini=min(x,mini);
      |                  ^