제출 #40536

#제출 시각아이디문제언어결과실행 시간메모리
40536mohammad_kilani구슬과 끈 (APIO14_beads)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define oo 1000000000 const double PI = acos(-1); const int N = 100010; vector< pair<int,int> > g[N]; int n , dp[N][2] , q[N], in[N]; int main(){ scanf("%d",&n); for(int i=0;i<n-1;i++){ int u , v; scanf("%d%d",&u,&v); g[u].push_back(v); g[v].push_back(u); } int ans = 0 , st = 0 , en = 0 , curnode , w , sum = 0 , mx = 0 , i = 0 , cnt = 0; for(int node=1;node<=n && cnt < 100;node++){ if(g[node].size() == 1){ cnt++; st = 0 , en = 0 ,sum = 0; for(i=1;i<=n;i++){ in[i] = g[i].size() - (i != node); if(in[i] == 0) q[en++] = i; } while(st < en){ curnode = q[st++]; dp[curnode][1] = dp[curnode][0] = 0; sum = 0 , mx = -oo; for(i=0;i<g[curnode].size();i++){ if(in[g[curnode][i].first] != 0){ w = g[curnode][i].second; in[g[curnode][i].first]--; if(in[g[curnode][i].first] == 0){ q[en++] = g[curnode][i].first; } } else{ sum += max(dp[g[curnode][i].first][0],dp[g[curnode][i].first][1]); mx = max(mx,dp[g[curnode][i].first][1] + g[curnode][i].second - max(dp[g[curnode][i].first][0],dp[g[curnode][i].first][1])); } } dp[curnode][1] = sum; dp[curnode][0] = sum + mx + w; } ans = max(ans,dp[node][1]); } } printf("%d\n",ans); return 0; }

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

beads.cpp: In function 'int main()':
beads.cpp:15:21: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(int&)'
     g[u].push_back(v);
                     ^
In file included from /usr/include/c++/7/vector:64:0,
                 from /usr/include/c++/7/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:86,
                 from beads.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:939:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]
       push_back(const value_type& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:939:7: note:   no known conversion for argument 1 from 'int' to 'const value_type& {aka const std::pair<int, int>&}'
/usr/include/c++/7/bits/stl_vector.h:953:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]
       push_back(value_type&& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:953:7: note:   no known conversion for argument 1 from 'int' to 'std::vector<std::pair<int, int> >::value_type&& {aka std::pair<int, int>&&}'
beads.cpp:16:21: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(int&)'
     g[v].push_back(u);
                     ^
In file included from /usr/include/c++/7/vector:64:0,
                 from /usr/include/c++/7/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:86,
                 from beads.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:939:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]
       push_back(const value_type& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:939:7: note:   no known conversion for argument 1 from 'int' to 'const value_type& {aka const std::pair<int, int>&}'
/usr/include/c++/7/bits/stl_vector.h:953:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]
       push_back(value_type&& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:953:7: note:   no known conversion for argument 1 from 'int' to 'std::vector<std::pair<int, int> >::value_type&& {aka std::pair<int, int>&&}'
beads.cpp:32:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
          for(i=0;i<g[curnode].size();i++){
                  ~^~~~~~~~~~~~~~~~~~
beads.cpp:11:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&n);
    ~~~~~^~~~~~~~~
beads.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&u,&v);
     ~~~~~^~~~~~~~~~~~~~