Submission #1068062

#TimeUsernameProblemLanguageResultExecution timeMemory
1068062kunzaZa183Torrent (COI16_torrent)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main(){ int n,st,ed; cin>>n>>st>>ed; st--,ed--; vector<vector<int>> adj(n); for(int i =0; i < n-1;i++) { int x,y; cin>>x>>y; x--,y--; adj[x].push_back(y),adj[y].push_back(x); } vector<int> bet(n); vector<int> path; function<void(int,int)> fp = [&](int cur,int par) { path.push_back(cur); if(cur==ed){ return; } for(auto a:adj[cur]) if(a!=par) { fp(a,cur); if(path.back()==ed) return; } path.pop_back(); }; fp(st,st); for(auto a:path) bet[a] = 1; auto valv = [&](vector<int> & vi) { if(vi.empty()) return 0; sort(vi.begin(),vi.end(),greater<int>()); for(int i = 0; i < vi.size();i++) vi[i] += i+1; return *max_element(vi.begin(),vi.end()); }; function<int(int,int)> outdp = [&](int cur,int par) { vector<int> vi; for(auto a:adj[cur]) if(a != par && bet[a] == 0) vi.push_back(outdp(a, cur)); return valv(vi); }; vector<int> dp(n); for(int i = 1; i < ((int) path.size()) - 1; i++) dp[path[i]] = outdp(path[i],path[i]); multiset<int> sst,sed; for(auto a:adj[st]) if(bet[a] == 0) { sst.insert(outdp(a,a)); } for(auto a:adj[ed]) if(bet[a] == 0) { sed.insert(outdp(a,a)); } int minans = n; multiset<int> vi,vi2; auto val = [](multiset<int> &msi) { if(msi.empty()) return 0; return int(msi.size()) + *msi.begin(); }; vector<int> pcomp1(path.size()),pcomp2(path.size()); multiset<int> idk1,idk2; for(int i = 1; i < path.size() - 1;i++){ if(i>1) { idk1.erase(idk1.find(dp[path[i-1]] + i - 2)); idk1.insert(dp[path[i-1]] + i - 1); } if(i>0) idk1.insert(dp[path[i]] + i - 1); pcomp1[i] = *idk1.rbegin(); } reverse(path.begin(),path.end()); for(int i = 1; i < path.size() - 1;i++){ if(i>1) { idk2.erase(idk2.find(dp[path[i-1]] + i - 2)); idk2.insert(dp[path[i-1]] + i - 1); } if(i>0) idk2.insert(dp[path[i]] + i - 1); pcomp2[i] = *idk2.rbegin(); } reverse(pcomp2.begin(),pcomp2.end()); // for(auto a:pcomp1) // cout<<a<<' '; // cout<<"\n"; // for(auto a:pcomp2) // cout<<a<<' '; // cout<<'\n'; reverse(path.begin(),path.end()); // for(auto a:path) // cout<<dp[a]<<" "; // cout<<"\n"; for(int i = 0; i < path.size() - 1;i++) { vector<int> vi1,vi2; for(auto a:sst) vi1.push_back(a); for(auto a:sed) vi2.push_back(a); if(i!=0) vi1.push_back(pcomp1[i]); if(i!=path.size() - 2) vi2.push_back(pcomp2[i + 1]); // for(auto a:vi1) // cout<<a<<" "; // cout<<"\n"; // for(auto a:vi2) // cout<<a<<" "; // cout<<"\n\n"; minans = min(minans,max(valv(vi1), valv(vi2))); } cout<<minans<<"\n"; }

Compilation message (stderr)

torrent.cpp: In lambda function:
torrent.cpp:43:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for(int i = 0; i < vi.size();i++)
      |                        ~~^~~~~~~~~~~
torrent.cpp:45:16: error: inconsistent types 'int' and 'long long int' deduced for lambda return type
   45 |         return *max_element(vi.begin(),vi.end());
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
torrent.cpp: In lambda function:
torrent.cpp:3:17: error: expected primary-expression before 'long'
    3 |     #define int long long
      |                 ^~~~
torrent.cpp:77:16: note: in expansion of macro 'int'
   77 |         return int(msi.size()) + *msi.begin();
      |                ^~~
torrent.cpp:77:15: error: expected ';' before 'long'
   77 |         return int(msi.size()) + *msi.begin();
      |               ^
      |               ;
torrent.cpp:3:17: error: expected primary-expression before 'long'
    3 |     #define int long long
      |                 ^~~~
torrent.cpp:77:16: note: in expansion of macro 'int'
   77 |         return int(msi.size()) + *msi.begin();
      |                ^~~
torrent.cpp: In function 'int main()':
torrent.cpp:82:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |       for(int i = 1; i < path.size() - 1;i++){
      |                      ~~^~~~~~~~~~~~~~~~~
torrent.cpp:93:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |       for(int i = 1; i < path.size() - 1;i++){
      |                      ~~^~~~~~~~~~~~~~~~~
torrent.cpp:116:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |       for(int i = 0; i < path.size() - 1;i++) {
      |                      ~~^~~~~~~~~~~~~~~~~
torrent.cpp:125:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |         if(i!=path.size() - 2)
      |            ~^~~~~~~~~~~~~~~~~
torrent.cpp:135:54: error: no matching function for call to 'min(long long int&, const int&)'
  135 |         minans = min(minans,max(valv(vi1), valv(vi2)));
      |                                                      ^
In file included 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 torrent.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:
torrent.cpp:135:54: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  135 |         minans = min(minans,max(valv(vi1), valv(vi2)));
      |                                                      ^
In file included 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 torrent.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:
torrent.cpp:135:54: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  135 |         minans = min(minans,max(valv(vi1), valv(vi2)));
      |                                                      ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from torrent.cpp:1:
/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:
torrent.cpp:135:54: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  135 |         minans = min(minans,max(valv(vi1), valv(vi2)));
      |                                                      ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from torrent.cpp:1:
/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:
torrent.cpp:135:54: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  135 |         minans = min(minans,max(valv(vi1), valv(vi2)));
      |                                                      ^