답안 #246465

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246465 2020-07-09T11:30:23 Z dantoh000 Pipes (CEOI15_pipes) C++14
컴파일 오류
0 ms 0 KB
#include <utility>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
using namespace std;
typedef pair<int,int> ii;
int n,m;
int d[100005], pa[100005], sz[100005];
vector<int> G[100005];
set<ii> bad;
struct ufds{
    int p[100005];
    ufds(){
        for (int i = 0; i <= 100000; i++) p[i] = i;
    }
    inline int find(int x){
        return p[x] == x ? x : p[x] = find(p[x]);
    }
    inline void un(int x, int y){
        p[x] = y;
    }
} u1 = ufds(), u2 = ufds();
void dfs(int u, int p){
    ///join at side bad
    u2.p[u] = u;
    pa[u] = p;
	for (auto v : G[u]){
		if (v == p) continue;
		else{
            d[v] = d[u]+1;
            dfs(v,u);
		}
	}
}

int main(){
    scanf("%d%d",&n,&m);
    for (int i = 1; i <= n; i++) sz[i] = 1; ///serious error
    for (int i = 0; i < m; i++){
        int u,v;
        scanf("%d%d",&u,&v);
        int pu = u1.find(u), pv = u1.find(v);
        //printf("%d -> %d, %d -> %d\n",u,pu,v,pv);
        if (pu == pv){
            //printf("update path %d %d\n",u,v);
            ///make all edges along this path bad
            ///all edges along path are only changed once, amortised O()
            u = u2.find(u), v = u2.find(v);
            while (u != v){
                if (d[u] < d[v]) swap(u,v);
                bad.insert({min(u,pa[u],max(u,pa[u])));
                //printf("bad %d %d\n",u,pa[u]);
              	u2.un(u,pa[u]);
                u = pa[u];
                u = u2.find(u);
            }
        }
        else{

            //printf("join %d %d\n",u,v);
            ///join the two components
            if (sz[pu] < sz[pv]){
                swap(pu,pv);
                swap(u,v);
            }
            ///join small v to big u
            u1.un(pv,pu);
            sz[pu] += sz[pv];
            ///add edge
            G[u].push_back(v);
            G[v].push_back(u);
            ///restart dfs
            d[v] = d[u]+1;
            dfs(v,u);

        }
    }
    for (int u = 1; u <= n ;u++){
        for (auto v : G[u]){
            if (v > u && bad.find({u,v}) == bad.end()){
                printf("%d %d\n",u,v);
            }
        }
    }
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:52:54: error: expected '}' before ')' token
                 bad.insert({min(u,pa[u],max(u,pa[u])));
                                                      ^
pipes.cpp:52:54: error: no matching function for call to 'std::set<std::pair<int, int> >::insert(<brace-enclosed initializer list>)'
In file included from /usr/include/c++/7/set:61:0,
                 from pipes.cpp:5:
/usr/include/c++/7/bits/stl_set.h:499:7: note: candidate: std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename __gnu_cxx::__alloc_traits<_Allocator>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename __gnu_cxx::__alloc_traits<_Allocator>::rebind<_Key>::other>::const_iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]
       insert(const value_type& __x)
       ^~~~~~
/usr/include/c++/7/bits/stl_set.h:499:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type& {aka const std::pair<int, int>&}'
/usr/include/c++/7/bits/stl_set.h:508:7: note: candidate: std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename __gnu_cxx::__alloc_traits<_Allocator>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename __gnu_cxx::__alloc_traits<_Allocator>::rebind<_Key>::other>::const_iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]
       insert(value_type&& __x)
       ^~~~~~
/usr/include/c++/7/bits/stl_set.h:508:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::set<std::pair<int, int> >::value_type&& {aka std::pair<int, int>&&}'
/usr/include/c++/7/bits/stl_set.h:536:7: note: candidate: std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, const value_type&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]
       insert(const_iterator __position, const value_type& __x)
       ^~~~~~
/usr/include/c++/7/bits/stl_set.h:536:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/7/bits/stl_set.h:541:7: note: candidate: std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]
       insert(const_iterator __position, value_type&& __x)
       ^~~~~~
/usr/include/c++/7/bits/stl_set.h:541:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/7/bits/stl_set.h:556:2: note: candidate: template<class _InputIterator> void std::set<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]
  insert(_InputIterator __first, _InputIterator __last)
  ^~~~~~
/usr/include/c++/7/bits/stl_set.h:556:2: note:   template argument deduction/substitution failed:
pipes.cpp:52:54: note:   candidate expects 2 arguments, 1 provided
                 bad.insert({min(u,pa[u],max(u,pa[u])));
                                                      ^
In file included from /usr/include/c++/7/set:61:0,
                 from pipes.cpp:5:
/usr/include/c++/7/bits/stl_set.h:568:7: note: candidate: void std::set<_Key, _Compare, _Alloc>::insert(std::initializer_list<_Tp>) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]
       insert(initializer_list<value_type> __l)
       ^~~~~~
/usr/include/c++/7/bits/stl_set.h:568:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::initializer_list<std::pair<int, int> >'
In file included from /usr/include/c++/7/vector:60:0,
                 from pipes.cpp:2:
/usr/include/c++/7/bits/stl_algobase.h: In instantiation of 'constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare) [with _Tp = int; _Compare = int]':
pipes.cpp:52:53:   required from here
/usr/include/c++/7/bits/stl_algobase.h:246:17: error: '__comp' cannot be used as a function
       if (__comp(__b, __a))
           ~~~~~~^~~~~~~~~~
pipes.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
pipes.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&u,&v);
         ~~~~~^~~~~~~~~~~~~~