Submission #893065

#TimeUsernameProblemLanguageResultExecution timeMemory
893065raul2008487Dreaming (IOI13_dreaming)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #include "dreaming.h" #define ll long long #define pll pair<ll,ll> #define vl vector<ll> #define in insert #define all(v) v.begin(),v.end() const int sz = 1e5+5; const ll inf = 1000000000000000; vector<pair<ll,ll>> adj[sz]; ll dis[sz][2], center, v1, v2, cnt = -1; bool used[sz]; vector<vector<ll>> path; void trav(ll node){ used[node] = 1; path[cnt].pb(node); for(pll edge: adj[node]){ if(!used[edge.fi]){ dfs(egde.fi); } } } void dfs(ll node, ll we, ll p){ if(we > mx){ v2 = node; mx = we; } for(pll edge: adj[node]){ if(edge.fi != p){ dfs(edge.fi, we + edge.se, node); } } } void caldis(ll node, ll we, ll p, ll type){ dis[node][type] = we; for(pll edge: adj[node]){ if(edge.fi != p){ dfs(edge.fi); } } } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { ll n = N, m = M, i, j, mx, ans = 0; for(i=1;i<=m;i++){ adj[A[i]].pb({B[i], T[i]}); adj[B[i]].pb({A[i], T[i]}); } for(i=0;i<n;i++){ if(!used[i]){ cnt++; path.pb(vl(0)); trav(i); } } array<ll, 3> bp = {-1, -1, -1}; for(i=0;i<c;i++){ mx = -1, v1 = -1, v2 = -1; dfs(path[i][0], 0, -1); v1 = v2; mx = -1; dfs(v1); caldis(v1, 0, -1, 0);caldis(v2, 0, -1, 1); ll pc = path[i][0], pb = max(dis[pc][0], dis[pc][1]); for(auto x: path[i]){ if(max(dis[x][0], dis[x][1]) > pb){ pc = x; pb = max(dis[x][0], dis[x][1]); } } ans = max(ans, pb); if(pb > bp[0]){ bp[2] = bp[1]; bp[1] = bp[0]; bp[0] = pb; } else if(pb > bp[1]){ bp[2] = bp[1]; bp[1] = pb; } else if(pb > bp[2]){ bp[2] = pb; } } ans = max(ans, bp[0] + bp[1] + L); if(bp[3] != -1){ ans = max(ans, bp[1] + bp[2] + 2*L); } return ans; }

Compilation message (stderr)

dreaming.cpp:10:1: error: 'vector' does not name a type
   10 | vector<pair<ll,ll>> adj[sz];
      | ^~~~~~
dreaming.cpp:13:1: error: 'vector' does not name a type
   13 | vector<vector<ll>> path;
      | ^~~~~~
dreaming.cpp: In function 'void trav(long long int)':
dreaming.cpp:16:5: error: 'path' was not declared in this scope; did you mean 'std::filesystem::__cxx11::path'?
   16 |     path[cnt].pb(node);
      |     ^~~~
      |     std::filesystem::__cxx11::path
In file included from /usr/include/c++/10/filesystem:45,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from dreaming.cpp:1:
/usr/include/c++/10/bits/fs_path.h:184:9: note: 'std::filesystem::__cxx11::path' declared here
  184 |   class path
      |         ^~~~
dreaming.cpp:4:13: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
    4 | #define pll pair<ll,ll>
      |             ^~~~
dreaming.cpp:17:9: note: in expansion of macro 'pll'
   17 |     for(pll edge: adj[node]){
      |         ^~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from dreaming.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'std::pair' declared here
  211 |     struct pair
      |            ^~~~
dreaming.cpp:3:12: error: expected primary-expression before 'long'
    3 | #define ll long long
      |            ^~~~
dreaming.cpp:4:18: note: in expansion of macro 'll'
    4 | #define pll pair<ll,ll>
      |                  ^~
dreaming.cpp:17:9: note: in expansion of macro 'pll'
   17 |     for(pll edge: adj[node]){
      |         ^~~
dreaming.cpp:22:1: error: expected primary-expression before '}' token
   22 | }
      | ^
dreaming.cpp:21:6: error: expected ';' before '}' token
   21 |     }
      |      ^
      |      ;
   22 | }
      | ~     
dreaming.cpp:22:1: error: expected primary-expression before '}' token
   22 | }
      | ^
dreaming.cpp:21:6: error: expected ')' before '}' token
   21 |     }
      |      ^
      |      )
   22 | }
      | ~     
dreaming.cpp:17:8: note: to match this '('
   17 |     for(pll edge: adj[node]){
      |        ^
dreaming.cpp:22:1: error: expected primary-expression before '}' token
   22 | }
      | ^
dreaming.cpp: In function 'void dfs(long long int, long long int, long long int)':
dreaming.cpp:24:13: error: 'mx' was not declared in this scope
   24 |     if(we > mx){
      |             ^~
dreaming.cpp:4:13: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
    4 | #define pll pair<ll,ll>
      |             ^~~~
dreaming.cpp:28:9: note: in expansion of macro 'pll'
   28 |     for(pll edge: adj[node]){
      |         ^~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from dreaming.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'std::pair' declared here
  211 |     struct pair
      |            ^~~~
dreaming.cpp:3:12: error: expected primary-expression before 'long'
    3 | #define ll long long
      |            ^~~~
dreaming.cpp:4:18: note: in expansion of macro 'll'
    4 | #define pll pair<ll,ll>
      |                  ^~
dreaming.cpp:28:9: note: in expansion of macro 'pll'
   28 |     for(pll edge: adj[node]){
      |         ^~~
dreaming.cpp:33:1: error: expected primary-expression before '}' token
   33 | }
      | ^
dreaming.cpp:32:6: error: expected ';' before '}' token
   32 |     }
      |      ^
      |      ;
   33 | }
      | ~     
dreaming.cpp:33:1: error: expected primary-expression before '}' token
   33 | }
      | ^
dreaming.cpp:32:6: error: expected ')' before '}' token
   32 |     }
      |      ^
      |      )
   33 | }
      | ~     
dreaming.cpp:28:8: note: to match this '('
   28 |     for(pll edge: adj[node]){
      |        ^
dreaming.cpp:33:1: error: expected primary-expression before '}' token
   33 | }
      | ^
dreaming.cpp: In function 'void caldis(long long int, long long int, long long int, long long int)':
dreaming.cpp:4:13: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
    4 | #define pll pair<ll,ll>
      |             ^~~~
dreaming.cpp:36:9: note: in expansion of macro 'pll'
   36 |     for(pll edge: adj[node]){
      |         ^~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from dreaming.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'std::pair' declared here
  211 |     struct pair
      |            ^~~~
dreaming.cpp:3:12: error: expected primary-expression before 'long'
    3 | #define ll long long
      |            ^~~~
dreaming.cpp:4:18: note: in expansion of macro 'll'
    4 | #define pll pair<ll,ll>
      |                  ^~
dreaming.cpp:36:9: note: in expansion of macro 'pll'
   36 |     for(pll edge: adj[node]){
      |         ^~~
dreaming.cpp:41:1: error: expected primary-expression before '}' token
   41 | }
      | ^
dreaming.cpp:40:6: error: expected ';' before '}' token
   40 |     }
      |      ^
      |      ;
   41 | }
      | ~     
dreaming.cpp:41:1: error: expected primary-expression before '}' token
   41 | }
      | ^
dreaming.cpp:40:6: error: expected ')' before '}' token
   40 |     }
      |      ^
      |      )
   41 | }
      | ~     
dreaming.cpp:36:8: note: to match this '('
   36 |     for(pll edge: adj[node]){
      |        ^
dreaming.cpp:41:1: error: expected primary-expression before '}' token
   41 | }
      | ^
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:45:9: error: 'adj' was not declared in this scope
   45 |         adj[A[i]].pb({B[i], T[i]});
      |         ^~~
dreaming.cpp:51:13: error: 'path' was not declared in this scope; did you mean 'std::filesystem::__cxx11::path'?
   51 |             path.pb(vl(0));
      |             ^~~~
      |             std::filesystem::__cxx11::path
In file included from /usr/include/c++/10/filesystem:45,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from dreaming.cpp:1:
/usr/include/c++/10/bits/fs_path.h:184:9: note: 'std::filesystem::__cxx11::path' declared here
  184 |   class path
      |         ^~~~
dreaming.cpp:5:12: error: 'vector' was not declared in this scope
    5 | #define vl vector<ll>
      |            ^~~~~~
dreaming.cpp:51:21: note: in expansion of macro 'vl'
   51 |             path.pb(vl(0));
      |                     ^~
dreaming.cpp:5:12: note: suggested alternatives:
    5 | #define vl vector<ll>
      |            ^~~~~~
dreaming.cpp:51:21: note: in expansion of macro 'vl'
   51 |             path.pb(vl(0));
      |                     ^~
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from dreaming.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:389:11: note:   'std::vector'
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from dreaming.cpp:1:
/usr/include/c++/10/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
dreaming.cpp:3:12: error: expected primary-expression before 'long'
    3 | #define ll long long
      |            ^~~~
dreaming.cpp:5:19: note: in expansion of macro 'll'
    5 | #define vl vector<ll>
      |                   ^~
dreaming.cpp:51:21: note: in expansion of macro 'vl'
   51 |             path.pb(vl(0));
      |                     ^~
dreaming.cpp:55:5: error: 'array' was not declared in this scope; did you mean 'std::array'?
   55 |     array<ll, 3> bp = {-1, -1, -1};
      |     ^~~~~
      |     std::array
In file included from /usr/include/c++/10/tuple:39,
                 from /usr/include/c++/10/functional:54,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from dreaming.cpp:1:
/usr/include/c++/10/array:94:12: note: 'std::array' declared here
   94 |     struct array
      |            ^~~~~
dreaming.cpp:3:12: error: expected primary-expression before 'long'
    3 | #define ll long long
      |            ^~~~
dreaming.cpp:55:11: note: in expansion of macro 'll'
   55 |     array<ll, 3> bp = {-1, -1, -1};
      |           ^~
dreaming.cpp:56:15: error: 'c' was not declared in this scope
   56 |     for(i=0;i<c;i++){
      |               ^
dreaming.cpp:58:13: error: 'path' was not declared in this scope; did you mean 'std::filesystem::__cxx11::path'?
   58 |         dfs(path[i][0], 0, -1);
      |             ^~~~
      |             std::filesystem::__cxx11::path
In file included from /usr/include/c++/10/filesystem:45,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from dreaming.cpp:1:
/usr/include/c++/10/bits/fs_path.h:184:9: note: 'std::filesystem::__cxx11::path' declared here
  184 |   class path
      |         ^~~~
dreaming.cpp:61:15: error: too few arguments to function 'void dfs(long long int, long long int, long long int)'
   61 |         dfs(v1);
      |               ^
dreaming.cpp:23:6: note: declared here
   23 | void dfs(ll node, ll we, ll p){
      |      ^~~
dreaming.cpp:65:16: error: 'max' was not declared in this scope; did you mean 'std::max'?
   65 |             if(max(dis[x][0], dis[x][1]) > pb){
      |                ^~~
      |                std::max
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from dreaming.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: 'std::max' declared here
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
dreaming.cpp:65:44: error: 'pb' was not declared in this scope; did you mean 'pc'?
   65 |             if(max(dis[x][0], dis[x][1]) > pb){
      |                                            ^~
      |                                            pc
dreaming.cpp:70:24: error: 'pb' was not declared in this scope; did you mean 'pc'?
   70 |         ans = max(ans, pb);
      |                        ^~
      |                        pc
dreaming.cpp:70:15: error: 'max' was not declared in this scope; did you mean 'std::max'?
   70 |         ans = max(ans, pb);
      |               ^~~
      |               std::max
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from dreaming.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: 'std::max' declared here
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
dreaming.cpp:71:17: error: 'bp' was not declared in this scope
   71 |         if(pb > bp[0]){
      |                 ^~
dreaming.cpp:84:20: error: 'bp' was not declared in this scope
   84 |     ans = max(ans, bp[0] + bp[1] + L);
      |                    ^~
dreaming.cpp:84:11: error: 'max' was not declared in this scope; did you mean 'std::max'?
   84 |     ans = max(ans, bp[0] + bp[1] + L);
      |           ^~~
      |           std::max
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from dreaming.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: 'std::max' declared here
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
dreaming.cpp:43:25: warning: unused variable 'j' [-Wunused-variable]
   43 |     ll n = N, m = M, i, j, mx, ans = 0;
      |                         ^