제출 #874110

#제출 시각아이디문제언어결과실행 시간메모리
874110theghostking1Friend (IOI14_friend)C++17
컴파일 에러
0 ms0 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; // Find out best sample int findSample(int n,int confidence[],int host[],int protocol[]){ bool istree = true; for (int i = 0; i<n; i++){ if (protocol[i] != 0) istree = false; } if (istree){ //root the tree //use stack to dfs stack<pair<int,pair<int,int>>> s; vector<bool> vis(n); vector<int> col(n); s.push({0,{0,-1}}); while (!s.empty()){ pair<int,pair<int,int>> a = s.top(); s.pop(); int node = a.first; int prev = a.second.second; int flag = a.second.first; col[node] = flag; vis[node] = true; for (auto u : adj[node]){ if (u == prev) continue; s.push({u,{1-flag,node}}); } } int one = 0; int zero = 0; for (int i = 0; i<n; i++){ if (col[i] == 0){ zero += confidence[i]; } else{ one += confidence[i]; } } return max(one,zero); } return ans; }

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

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:26:18: error: 'adj' was not declared in this scope
   26 |    for (auto u : adj[node]){
      |                  ^~~
friend.cpp:28:29: error: no matching function for call to 'std::stack<std::pair<int, std::pair<int, int> > >::push(<brace-enclosed initializer list>)'
   28 |     s.push({u,{1-flag,node}});
      |                             ^
In file included from /usr/include/c++/10/stack:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:89,
                 from friend.cpp:2:
/usr/include/c++/10/bits/stl_stack.h:239:7: note: candidate: 'void std::stack<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::pair<int, std::pair<int, int> >; _Sequence = std::deque<std::pair<int, std::pair<int, int> >, std::allocator<std::pair<int, std::pair<int, int> > > >; std::stack<_Tp, _Sequence>::value_type = std::pair<int, std::pair<int, int> >]'
  239 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_stack.h:239:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<int, std::pair<int, int> >&'}
  239 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_stack.h:244:7: note: candidate: 'void std::stack<_Tp, _Sequence>::push(std::stack<_Tp, _Sequence>::value_type&&) [with _Tp = std::pair<int, std::pair<int, int> >; _Sequence = std::deque<std::pair<int, std::pair<int, int> >, std::allocator<std::pair<int, std::pair<int, int> > > >; std::stack<_Tp, _Sequence>::value_type = std::pair<int, std::pair<int, int> >]'
  244 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_stack.h:244:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::stack<std::pair<int, std::pair<int, int> > >::value_type&&' {aka 'std::pair<int, std::pair<int, int> >&&'}
  244 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
friend.cpp:43:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   43 |  return ans;
      |         ^~~
      |         abs