Language: C++

#include<bits/stdc++.h>
using namespace std;
int a,s,d[100002],f,g,h,j,k,l,i,n,m;
vector<int> v[100002];
vector<int> v1,v2;
void prnt(vector<int> v){
    swap(v[v.size()-1],swap(v[v.size()-2]));
    for(auto it:v){
        printf("%d ",it);
    }
}
void dfs(int idx,int par){
    int l=-1,t=++g,ff=0;
    //cout<<t<<" "<<idx<<endl;
    for(auto it:v[idx]) {if(it==par) continue;if(v[it].size()>1) ff++;}

    if(ff>1)return;
    for(auto it:v[idx]){
        if(it==par) continue;
        if(v[it].size()>1) l=it; else
        {v1.push_back(++g);}
    }
    v1.push_back(t);
        //v1.push_back(++g);
   //cout<<idx<<"&";
    if(l!=-1)dfs(l,idx);
}
main(){
    cin>>n;
    for(i=0;i<n-1;i++){
        scanf("%d%d",&a,&s);
        v[a].push_back(s);
        v[s].push_back(a);
    }

    for(i=1;i<=n;i++){
        l=0;
        for(auto it:v[i]){
            if(v[it].size()>1) l++;
        }
        if(l>2) {cout<<-1;return 0;}
    }

    for(i=1;i<=n;i++){
        if(v[i].size()>1) continue;
        if(d[v[i][0]]) continue;
        d[v[i][0]]=1;
        cout<<endl;
        if(!j) {g=0;dfs(i,0);if(v1.size()==n)v2=v1;v1.clear();} else {g=0;dfs(i,0);break;}
    }

    if(!v1.size() || v1>v2) prnt(v2); else prnt(v1);
}


Compiler output:
a.cc: In function 'void prnt(std::vector<int>)':
a.cc:7:28: error: no matching function for call to 'swap(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
    7 |     swap(v[v.size()-1],swap(v[v.size()-2]));
      |                        ~~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
                 from a.cc:1:
/usr/include/c++/14/sstream:1204:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(basic_stringbuf<_CharT, _Traits, _Alloc>&, basic_stringbuf<_CharT, _Traits, _Alloc>&)'
 1204 |     swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x,
      |     ^~~~
/usr/include/c++/14/sstream:1204:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/sstream:1212:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(basic_istringstream<_CharT, _Traits, _Allocator>&, basic_istringstream<_CharT, _Traits, _Allocator>&)'
 1212 |     swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x,
      |     ^~~~
/usr/include/c++/14/sstream:1212:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/sstream:1219:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(basic_ostringstream<_CharT, _Traits, _Allocator>&, basic_ostringstream<_CharT, _Traits, _Allocator>&)'
 1219 |     swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x,
      |     ^~~~
/usr/include/c++/14/sstream:1219:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/sstream:1226:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(basic_stringstream<_CharT, _Traits, _Allocator>&, basic_stringstream<_CharT, _Traits, _Allocator>&)'
 1226 |     swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x,
      |     ^~~~
/usr/include/c++/14/sstream:1226:5: note:   candidate expects 2 arguments, 1 provided
In file included from /usr/include/c++/14/regex:68,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181:
/usr/include/c++/14/bits/regex.h:896:5: note: candidate: 'template<class _Ch_type, class _Rx_traits> void std::__cxx11::swap(basic_regex<_Ch_type, _Rx_traits>&, basic_regex<_Ch_type, _Rx_traits>&)'
  896 |     swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
      |     ^~~~
/usr/include/c++/14/bits/regex.h:896:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/regex.h:2230:5: note: candidate: 'template<class _Bi_iter, class _Alloc> void std::__cxx11::swap(match_results<_BiIter, _Alloc>&, match_results<_BiIter, _Alloc>&)'
 2230 |     swap(match_results<_Bi_iter, _Alloc>& __lhs,
      |     ^~~~
/usr/include/c++/14/bits/regex.h:2230:5: note:   candidate expects 2 arguments, 1 provided
In file included from /usr/include/c++/14/bits/stl_pair.h:61,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/move.h:226:5: note: candidate: 'template<class _Tp> std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&)'
  226 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/14/bits/move.h:226:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/move.h:250:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> std::__enable_if_t<((bool)std::__is_swappable<_Tp>::value)> std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])'
  250 |     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
      |     ^~~~
/usr/include/c++/14/bits/move.h:250:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_pair.h:1089:5: note: candidate: 'template<class _T1, class _T2> typename std::enable_if<std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value>::type std::swap(pair<_T1, _T2>&, pair<_T1, _T2>&)'
 1089 |     swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
      |     ^~~~
/usr/include/c++/14/bits/stl_pair.h:1089:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_pair.h:1106:5: note: candidate: 'template<class _T1, class _T2> typename std::enable_if<(! std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value)>::type std::swap(pair<_T1, _T2>&, pair<_T1, _T2>&)' (deleted)
 1106 |     swap(pair<_T1, _T2>&, pair<_T1, _T2>&) = delete;
      |     ^~~~
/usr/include/c++/14/bits/stl_pair.h:1106:5: note:   candidate expects 2 arguments, 1 provided
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/basic_string.h:4039:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> void std::swap(__cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 4039 |     swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~
/usr/include/c++/14/bits/basic_string.h:4039:5: note:   candidate expects 2 arguments, 1 provided
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68:
/usr/include/c++/14/tuple:2805:5: note: candidate: 'template<class ... _Elements> typename std::enable_if<std::__and_<std::__is_swappable<_Elements>...>::value>::type std::swap(tuple<_UTypes ...>&, tuple<_UTypes ...>&)'
 2805 |     swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
      |     ^~~~
/usr/include/c++/14/tuple:2805:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/tuple:2823:5: note: candidate: 'template<class ... _Elements> typename std::enable_if<(! std::__and_<std::__is_swappable<_Elements>...>::value)>::type std::swap(tuple<_UTypes ...>&, tuple<_UTypes ...>&)' (deleted)
 2823 |     swap(tuple<_Elements...>&, tuple<_Elements...>&) = delete;
      |     ^~~~
/usr/include/c++/14/tuple:2823:5: note:   candidate expects 2 arguments, 1 provided
In file included from /usr/include/c++/14/functional:59,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/std_function.h:782:5: note: candidate: 'template<class _Res, class ... _Args> void std::swap(function<_Res(_ArgTypes ...)>&, function<_Res(_ArgTypes ...)>&)'
  782 |     swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y) noexcept
      |     ^~~~
/usr/include/c++/14/bits/std_function.h:782:5: note:   candidate expects 2 arguments, 1 provided
In file included from /usr/include/c++/14/unordered_map:41,
                 from /usr/include/c++/14/functional:63:
/usr/include/c++/14/bits/unordered_map.h:2130:5: note: candidate: 'template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> void std::swap(unordered_map<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&, unordered_map<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&)'
 2130 |     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
      |     ^~~~
/usr/include/c++/14/bits/unordered_map.h:2130:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/unordered_map.h:2137:5: note: candidate: 'template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> void std::swap(unordered_multimap<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&, unordered_multimap<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&)'
 2137 |     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
      |     ^~~~
/usr/include/c++/14/bits/unordered_map.h:2137:5: note:   candidate expects 2 arguments, 1 provided
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64:
/usr/include/c++/14/bits/stl_vector.h:2122:5: note: candidate: 'template<class _Tp, class _Alloc> void std::swap(vector<_Tp, _Alloc>&, vector<_Tp, _Alloc>&)'
 2122 |     swap(vector<_Tp, _Alloc>& __x, vector<_Tp, _Alloc>& __y)
      |     ^~~~
/usr/include/c++/14/bits/stl_vector.h:2122:5: note:   candidate expects 2 arguments, 1 provided
In file included from /usr/include/c++/14/functional:65:
/usr/include/c++/14/array:377:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> std::__enable_if_t<((bool)typename std::__array_traits<_Tp, _Nm>::_Is_swappable::value)> std::swap(array<_Tp, _Nm>&, array<_Tp, _Nm>&)'
  377 |     swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
      |     ^~~~
/usr/include/c++/14/array:377:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/array:384:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> std::__enable_if_t<((bool)(! typename std::__array_traits<_Tp, _Nm>::_Is_swappable::value))> std::swap(array<_Tp, _Nm>&, array<_Tp, _Nm>&)' (deleted)
  384 |     swap(array<_Tp, _Nm>&, array<_Tp, _Nm>&) = delete;
      |     ^~~~
/usr/include/c++/14/array:384:5: note:   candidate expects 2 arguments, 1 provided
In file included from /usr/include/c++/14/memory:78,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:56:
/usr/include/c++/14/bits/unique_ptr.h:822:5: note: candidate: 'template<class _Tp, class _Dp> typename std::enable_if<std::__is_swappable<_T2>::value>::type std::swap(unique_ptr<_Tp, _Dp>&, unique_ptr<_Tp, _Dp>&)'
  822 |     swap(unique_ptr<_Tp, _Dp>& __x,
      |     ^~~~
/usr/include/c++/14/bits/unique_ptr.h:822:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/unique_ptr.h:829:5: note: candidate: 'template<class _Tp, class _Dp> typename std::enable_if<(! std::__is_swappable<_T2>::value)>::type std::swap(unique_ptr<_Tp, _Dp>&, unique_ptr<_Tp, _Dp>&)' (deleted)
  829 |     swap(unique_ptr<_Tp, _Dp>&,
      |     ^~~~
/usr/include/c++/14/bits/unique_ptr.h:829:5: note:   candidate expects 2 arguments, 1 provided
In file included from /usr/include/c++/14/bits/shared_ptr.h:53,
                 from /usr/include/c++/14/memory:80:
/usr/include/c++/14/bits/shared_ptr_base.h:1921:5: note: candidate: 'template<class