제출 #676707

#제출 시각아이디문제언어결과실행 시간메모리
676707QwertyPiIslands (IOI08_islands)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #define fi first #define se second using namespace std; const int N = 1e6 + 11; // 70 vector<vector<pair<int, int>>> G[N]; // 32 int p[N], w[N], tin[N], t = 0; long long dp[N]; bool vis[N], cyc[N]; // 12 struct edge{ int u, v, w; }; vector<edge> extra; void dfs(int id, int v, int pa = -1){ vis[v] = true; tin[v] = ++t; for(auto i : G[v]){ if(!vis[i.fi]){ p[i.fi] = v; dfs(id, i.fi, v); w[i.fi] = i.se; }else if(i.fi != pa){ extra[id] = {v, i.fi, i.se}; } } } bool is_anc(int u, int v){ return tin[u] <= tin[v]; } long long dfs_dp(int id, int v, int pa = -1){ long long mx1 = 0, mx2 = 0; long long ans = 0; for(auto i : G[v]){ if(!cyc[i.fi] && i.fi != pa){ long long r = dfs_dp(id, i.fi, v); ans = max(ans, r); long long v = dp[i.fi] + i.se; if(v > mx1) mx2 = mx1, mx1 = v; else if(v > mx2) mx2 = v; } } ans = max(ans, mx1 + mx2); dp[v] = mx1; return ans; } long long solve(int id, vector<long long>& DP, vector<long long>& W){ int n = W.size(); for(int i = 0; i < n; i++){ W.push_back(W[i]); } W.push_back(0); for(int i = (int) W.size() - 2; i >= 0; i--){ W[i] = W[i + 1] - W[i]; } // 4 deque<int> v; for(int i = 0; i < n; i++){ while(v.size() && DP[i] + W[i] >= DP[v.back()] + W[v.back()]) v.pop_back(); v.push_back(i); } long long ans = 0; for(int i = 0; i < n; i++){ if(v.front() == i) v.pop_front(); ans = max(ans, DP[i] - W[i] + DP[v.front() % n] + W[v.front()]); while(v.size() && DP[i] + W[i + n] >= DP[v.back() % n] + W[v.back()]) v.pop_back(); v.push_back(i + n); } return ans; } int32_t main(){ cin.tie(0); cout.tie(0)->sync_with_stdio(false); int n; cin >> n; for(int i = 1; i <= n; i++){ int v, _w; cin >> v >> _w; G[i].push_back({v, _w}); G[v].push_back({i, _w}); } for(int i = 1; i <= n; i++){ G[i].shrink_to_fit(); } /* for(int i = 1; i <= n; i++){ if(!vis[i]){ extra.resize(extra.size() + 1); dfs(extra.size() - 1, i); } } // 20 int CC = extra.size(); long long ans = 0; for(int i = 0; i < CC; i++){ vector<int> cyc_L, cyc_R; int x = extra[i].u, y = extra[i].v; while(!is_anc(x, y)){ cyc[x] = true; cyc_L.push_back(x); x = p[x]; } while(!is_anc(y, x)){ cyc[y] = true; cyc_R.push_back(y); y = p[y]; } int l = x; cyc[l] = true; long long rans = 0; for(auto v : cyc_L){ rans = max(rans, dfs_dp(i, v)); } for(auto v : cyc_R){ rans = max(rans, dfs_dp(i, v)); } rans = max(rans, dfs_dp(i, l)); vector<long long> W, DP; for(auto i : cyc_L){ DP.push_back(dp[i]); W.push_back(w[i]); } DP.push_back(dp[l]); for(int i = (int) cyc_R.size() - 1; i >= 0; i--){ DP.push_back(dp[cyc_R[i]]); W.push_back(w[cyc_R[i]]); } cyc_L.resize(0); cyc_R.resize(0); W.push_back(extra[i].w); rans = max(rans, solve(i, DP, W)); ans += rans; } */ cout << ans << endl; }

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

islands.cpp: In function 'void dfs(int, int, int)':
islands.cpp:2:12: error: 'class std::vector<std::pair<int, int> >' has no member named 'first'
    2 | #define fi first
      |            ^~~~~
islands.cpp:25:13: note: in expansion of macro 'fi'
   25 |   if(!vis[i.fi]){
      |             ^~
islands.cpp:2:12: error: 'class std::vector<std::pair<int, int> >' has no member named 'first'
    2 | #define fi first
      |            ^~~~~
islands.cpp:26:8: note: in expansion of macro 'fi'
   26 |    p[i.fi] = v;
      |        ^~
islands.cpp:2:12: error: 'class std::vector<std::pair<int, int> >' has no member named 'first'
    2 | #define fi first
      |            ^~~~~
islands.cpp:27:14: note: in expansion of macro 'fi'
   27 |    dfs(id, i.fi, v);
      |              ^~
islands.cpp:2:12: error: 'class std::vector<std::pair<int, int> >' has no member named 'first'
    2 | #define fi first
      |            ^~~~~
islands.cpp:28:8: note: in expansion of macro 'fi'
   28 |    w[i.fi] = i.se;
      |        ^~
islands.cpp:3:12: error: 'class std::vector<std::pair<int, int> >' has no member named 'second'
    3 | #define se second
      |            ^~~~~~
islands.cpp:28:16: note: in expansion of macro 'se'
   28 |    w[i.fi] = i.se;
      |                ^~
islands.cpp:2:12: error: 'class std::vector<std::pair<int, int> >' has no member named 'first'
    2 | #define fi first
      |            ^~~~~
islands.cpp:29:14: note: in expansion of macro 'fi'
   29 |   }else if(i.fi != pa){
      |              ^~
islands.cpp:2:12: error: 'class std::vector<std::pair<int, int> >' has no member named 'first'
    2 | #define fi first
      |            ^~~~~
islands.cpp:30:22: note: in expansion of macro 'fi'
   30 |    extra[id] = {v, i.fi, i.se};
      |                      ^~
islands.cpp:3:12: error: 'class std::vector<std::pair<int, int> >' has no member named 'second'
    3 | #define se second
      |            ^~~~~~
islands.cpp:30:28: note: in expansion of macro 'se'
   30 |    extra[id] = {v, i.fi, i.se};
      |                            ^~
islands.cpp:30:30: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<edge>, edge>::value_type' {aka 'edge'} and '<brace-enclosed initializer list>')
   30 |    extra[id] = {v, i.fi, i.se};
      |                              ^
islands.cpp:17:8: note: candidate: 'constexpr edge& edge::operator=(const edge&)'
   17 | struct edge{
      |        ^~~~
islands.cpp:17:8: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const edge&'
islands.cpp:17:8: note: candidate: 'constexpr edge& edge::operator=(edge&&)'
islands.cpp:17:8: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'edge&&'
islands.cpp: In function 'long long int dfs_dp(int, int, int)':
islands.cpp:2:12: error: 'class std::vector<std::pair<int, int> >' has no member named 'first'
    2 | #define fi first
      |            ^~~~~
islands.cpp:43:13: note: in expansion of macro 'fi'
   43 |   if(!cyc[i.fi] && i.fi != pa){
      |             ^~
islands.cpp:2:12: error: 'class std::vector<std::pair<int, int> >' has no member named 'first'
    2 | #define fi first
      |            ^~~~~
islands.cpp:43:22: note: in expansion of macro 'fi'
   43 |   if(!cyc[i.fi] && i.fi != pa){
      |                      ^~
islands.cpp:2:12: error: 'class std::vector<std::pair<int, int> >' has no member named 'first'
    2 | #define fi first
      |            ^~~~~
islands.cpp:44:31: note: in expansion of macro 'fi'
   44 |    long long r = dfs_dp(id, i.fi, v);
      |                               ^~
islands.cpp:2:12: error: 'class std::vector<std::pair<int, int> >' has no member named 'first'
    2 | #define fi first
      |            ^~~~~
islands.cpp:46:23: note: in expansion of macro 'fi'
   46 |    long long v = dp[i.fi] + i.se;
      |                       ^~
islands.cpp:3:12: error: 'class std::vector<std::pair<int, int> >' has no member named 'second'
    3 | #define se second
      |            ^~~~~~
islands.cpp:46:31: note: in expansion of macro 'se'
   46 |    long long v = dp[i.fi] + i.se;
      |                               ^~
islands.cpp: In function 'int32_t main()':
islands.cpp:85:25: error: no matching function for call to 'std::vector<std::vector<std::pair<int, int> > >::push_back(<brace-enclosed initializer list>)'
   85 |   G[i].push_back({v, _w});
      |                         ^
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 islands.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::vector<std::pair<int, int> >; _Alloc = std::allocator<std::vector<std::pair<int, int> > >; std::vector<_Tp, _Alloc>::value_type = std::vector<std::pair<int, int> >]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::vector<std::pair<int, int> >&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::vector<std::pair<int, int> >; _Alloc = std::allocator<std::vector<std::pair<int, int> > >; std::vector<_Tp, _Alloc>::value_type = std::vector<std::pair<int, int> >]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::vector<std::pair<int, int> > >::value_type&&' {aka 'std::vector<std::pair<int, int> >&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
islands.cpp:86:25: error: no matching function for call to 'std::vector<std::vector<std::pair<int, int> > >::push_back(<brace-enclosed initializer list>)'
   86 |   G[v].push_back({i, _w});
      |                         ^
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 islands.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::vector<std::pair<int, int> >; _Alloc = std::allocator<std::vector<std::pair<int, int> > >; std::vector<_Tp, _Alloc>::value_type = std::vector<std::pair<int, int> >]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::vector<std::pair<int, int> >&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::vector<std::pair<int, int> >; _Alloc = std::allocator<std::vector<std::pair<int, int> > >; std::vector<_Tp, _Alloc>::value_type = std::vector<std::pair<int, int> >]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::vector<std::pair<int, int> > >::value_type&&' {aka 'std::vector<std::pair<int, int> >&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
islands.cpp:142:10: error: 'ans' was not declared in this scope; did you mean 'abs'?
  142 |  cout << ans << endl;
      |          ^~~
      |          abs