답안 #317111

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
317111 2020-10-29T03:35:01 Z caoash Potemkin cycle (CEOI15_indcyc) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h> 
using namespace std;
 
using ll = long long;
 
using vi = vector<int>;
using vl = vector<ll>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
 
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
 
namespace output {
  void pr(int x) {
    cout << x;
  }
  void pr(long x) {
    cout << x;
  }
  void pr(ll x) {
    cout << x;
  }
  void pr(unsigned x) {
    cout << x;
  }
  void pr(unsigned long x) {
    cout << x;
  }
  void pr(unsigned long long x) {
    cout << x;
  }
  void pr(float x) {
    cout << x;
  }
  void pr(double x) {
    cout << x;
  }
  void pr(long double x) {
    cout << x;
  }
  void pr(char x) {
    cout << x;
  }
  void pr(const char * x) {
    cout << x;
  }
  void pr(const string & x) {
    cout << x;
  }
  void pr(bool x) {
    pr(x ? "true" : "false");
  }
 
  template < class T1, class T2 > void pr(const pair < T1, T2 > & x);
  template < class T > void pr(const T & x);
 
  template < class T, class...Ts > void pr(const T & t,
    const Ts & ...ts) {
    pr(t);
    pr(ts...);
  }
  template < class T1, class T2 > void pr(const pair < T1, T2 > & x) {
    pr("{", x.f, ", ", x.s, "}");
  }
  template < class T > void pr(const T & x) {
    pr("{"); // const iterator needed for vector<bool>
    bool fst = 1;
    for (const auto & a: x) pr(!fst ? ", " : "", a), fst = 0;
    pr("}");
  }
 
  void ps() {
    pr("\n");
  } // print w/ spaces
  template < class T, class...Ts > void ps(const T & t,
    const Ts & ...ts) {
    pr(t);
    if (sizeof...(ts)) pr(" ");
    ps(ts...);
  }
 
  void pc() {
    cout << "]" << endl;
  } // debug w/ commas
  template < class T, class...Ts > void pc(const T & t,
    const Ts & ...ts) {
    pr(t);
    if (sizeof...(ts)) pr(", ");
    pc(ts...);
  }
  #define dbg(x...) pr("[", #x, "] = ["), pc(x);
}
 
#ifndef ONLINE_JUDGE
using namespace output;
#else
using namespace output;
#define dbg(x...)
#endif
 
const int MX = 2000;
const int MOD = (int) (1e9 + 7);
const ll INF = (ll) 1e18;
 
int n, m;
 
int inc(int u, int v) {
    return MX * u + v;
}
 
set<int> adj[MX];
vi fin[MX * MX];
bool vis[MX * MX];
bool done[MX * MX];
vector<pi> ed;
int anc[MX * MX];
bool found = false;
vi ret;
 
int cnt = 0;

void dfs(int v, int p) {
    if (found) return;
    vis[v] = true;
    // dbg(v, p);
    for (int to : fin[v]) {
        if (found) return;
        if (!done[to]) {
            if (!found && vis[to]) {
                ++cnt;
                found = true;
                int curr = v;
                // dbg(curr, to);
                while(curr != to) {
                    // dbg(curr);
                    ret.pb((curr % 2000) + 1);
                    curr = anc[curr];
                }
                // dbg(to);
                ret.pb((to % 2000) + 1);
                return;
            } else {
                anc[to] = v;
                // dbg("GO", to/2000, to%2000);
                dfs(to, v);
            }
        }
    }
    done[v] = true;
}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m; 
    for (int i = 0; i < m; i++) {
        int u, v; cin >> u >> v;
        u--, v--;
        adj[u].insert(v), adj[v].insert(u);
        ed.pb(mp(u, v));
        ed.pb(mp(v, u));
    }
    vector<pi> nods;
    for (int i = 0; i < sz(ed); i++) {
        int u = ed[i].f, v = ed[i].s;
        for (int j = 0; j < n; j++) {
            // dbg(u, v, j, adj[v].count(j), adj[u].count(j));
            if (j != u && j != v && adj[v].count(j) && !adj[u].count(j)) {
                // dbg(u, v, v, j);
                // ps(inc(u, v), inc(v, j));
                fin[inc(u, v)].pb(inc(v, j));
                nods.insert(mp(u, v));
                nods.insert(mp(v, j));
            }
        }
    }
    for (auto &x : nods) {
        // dbg(x.f, x.s);
        // if (deg[inc(x.f, x.s)] != 0) continue;
        if (found) break;
        if (!done[inc(x.f, x.s)]) dfs(inc(x.f, x.s), -1);
    }
    if (!found) cout << "no" << '\n';
    else {
        for (auto x : ret) {
            cout << x << " ";
        }
    }
}

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:177:37: error: no matching function for call to 'std::vector<std::pair<int, int> >::insert(std::pair<int, int>)'
  177 |                 nods.insert(mp(u, v));
      |                                     ^
In file included from /usr/include/c++/9/vector:72,
                 from /usr/include/c++/9/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:86,
                 from indcyc.cpp:1:
/usr/include/c++/9/bits/vector.tcc:130:5: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = std::pair<int, int>*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const std::pair<int, int>*, std::vector<std::pair<int, int> > >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const std::pair<int, int>*; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
  130 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/vector.tcc:130:5: note:   candidate expects 2 arguments, 1 provided
In file included from /usr/include/c++/9/vector:67,
                 from /usr/include/c++/9/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:86,
                 from indcyc.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:1290:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = std::pair<int, int>*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const std::pair<int, int>*, std::vector<std::pair<int, int> > >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const std::pair<int, int>*; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1290 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_vector.h:1290:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/9/bits/stl_vector.h:1307:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::initializer_list<_Tp>) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = std::pair<int, int>*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const std::pair<int, int>*, std::vector<std::pair<int, int> > >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const std::pair<int, int>*]'
 1307 |       insert(const_iterator __position, initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_vector.h:1307:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/9/bits/stl_vector.h:1332:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = std::pair<int, int>*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const std::pair<int, int>*, std::vector<std::pair<int, int> > >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const std::pair<int, int>*; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1332 |       insert(const_iterator __position, size_type __n, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_vector.h:1332:7: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/9/bits/stl_vector.h:1376:2: note: candidate: 'template<class _InputIterator, class> std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, _InputIterator, _InputIterator) [with _InputIterator = _InputIterator; <template-parameter-2-2> = <template-parameter-1-2>; _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >]'
 1376 |  insert(const_iterator __position, _InputIterator __first,
      |  ^~~~~~
/usr/include/c++/9/bits/stl_vector.h:1376:2: note:   template argument deduction/substitution failed:
indcyc.cpp:177:37: note:   candidate expects 3 arguments, 1 provided
  177 |                 nods.insert(mp(u, v));
      |                                     ^
indcyc.cpp:178:37: error: no matching function for call to 'std::vector<std::pair<int, int> >::insert(std::pair<int, int>)'
  178 |                 nods.insert(mp(v, j));
      |                                     ^
In file included from /usr/include/c++/9/vector:72,
                 from /usr/include/c++/9/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:86,
                 from indcyc.cpp:1:
/usr/include/c++/9/bits/vector.tcc:130:5: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = std::pair<int, int>*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const std::pair<int, int>*, std::vector<std::pair<int, int> > >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const std::pair<int, int>*; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
  130 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/vector.tcc:130:5: note:   candidate expects 2 arguments, 1 provided
In file included from /usr/include/c++/9/vector:67,
                 from /usr/include/c++/9/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:86,
                 from indcyc.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:1290:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = std::pair<int, int>*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const std::pair<int, int>*, std::vector<std::pair<int, int> > >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const std::pair<int, int>*; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1290 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_vector.h:1290:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/9/bits/stl_vector.h:1307:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::initializer_list<_Tp>) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = std::pair<int, int>*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const std::pair<int, int>*, std::vector<std::pair<int, int> > >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const std::pair<int, int>*]'
 1307 |       insert(const_iterator __position, initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_vector.h:1307:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/9/bits/stl_vector.h:1332:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = std::pair<int, int>*; std::vector<_Tp, _Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const std::pair<int, int>*, std::vector<std::pair<int, int> > >; typename __gnu_cxx::__alloc_traits<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_pointer = const std::pair<int, int>*; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1332 |       insert(const_iterator __position, size_type __n, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/9/bits/stl_vector.h:1332:7: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/9/bits/stl_vector.h:1376:2: note: candidate: 'template<class _InputIterator, class> std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::const_iterator, _InputIterator, _InputIterator) [with _InputIterator = _InputIterator; <template-parameter-2-2> = <template-parameter-1-2>; _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >]'
 1376 |  insert(const_iterator __position, _InputIterator __first,
      |  ^~~~~~
/usr/include/c++/9/bits/stl_vector.h:1376:2: note:   template argument deduction/substitution failed:
indcyc.cpp:178:37: note:   candidate expects 3 arguments, 1 provided
  178 |                 nods.insert(mp(v, j));
      |                                     ^