Submission #25726

#TimeUsernameProblemLanguageResultExecution timeMemory
25726gs14004Pipes (CEOI15_pipes)C++11
Compilation error
0 ms0 KiB
#include <cstdio> #include <vector> #include <algorithm> using namespace std; typedef pair<int,int> pi; struct disj{ int pa[100005]; void init(int n){ for(int i=0; i<=n; i++) pa[i] = i; } int find(int x){ return pa[x] = (pa[x] == x ? x : find(pa[x])); } bool uni(int p, int q){ p = find(p); q = find(q); if(p == q) return 0; pa[q] = p; find(q); return 1; } }disj1, disj2; int n, m; vector<pi> tree, bri; vector<int> graph[100005]; int par[100005][17], dep[100005]; bool vis[100005]; void dfs(int x, int pa){ vis[x] = 1; par[x][0] = pa; for(int i=1; i<17; i++){ par[x][i] = par[par[x][i-1]][i-1]; } for (auto &i : graph[x]){ if(i == pa) continue; dep[i] = dep[x] + 1; dfs(i,x); } } int lca(int x, int y){ if(dep[x] < dep[y]) swap(x,y); int dx = dep[x] - dep[y]; for(int i=0; i<17; i++){ if((dx >> i) & 1) x = par[x][i]; } for(int i=16; i>=0; i--){ if(par[x][i] != par[y][i]){ x = par[x][i]; y = par[y][i]; } } if(x != y) x = par[x][0]; return x; } int up[100005]; void dfs2(int x, int pa){ for (auto &i : graph[x]){ if(i == pa) continue; dfs2(i,x); up[x] = max(up[x], up[i] - 1); } if(pa != 0 && up[x] == 0) printf("%d %d\n",pa,x); } int main(){ scanf("%d %d\n",&n,&m); disj1.init(n); disj2.init(n); while(m--){ int u = 0, v = 0; char str[15]; fgets(str,15,stdin); int pos = 0; while(str[pos] != ' '){ u = (10 * u) + (str[pos] - '0'); pos++; } pos++; while(str[pos] != '\n' && str[pos]){ v = (10 * v) + (str[pos] - '0'); pos++; } if(disj1.uni(u,v)){ tree.push_back(pi(u,v)); } else if(disj2.uni(u,v)){ bri.push_back(pi(u,v)); } } for(auto &i : tree){ graph[i.first].push_back(i.second); graph[i.second].push_back(i.first); } auto cmp = [&](const pi &a, const pi &b){ return disj1.find(a.first) < disj1.find(b.first); }; sort(bri.begin(), bri.end(), cmp); for(int i=1; i<=n; i++){ if(!vis[i]){ int pos = disj1.find(i); dfs(pos,0); int p = lower_bound(bri.begin(), bri.end(), pi(pos, -1), cmp) - bri.begin(); while(p < bri.end() && disj1.find(bri[p].first) != pos){ pi i = bri[p++]; int l = lca(i.first,i.second); up[i.first] = max(up[i.first],dep[i.first] - dep[l]); up[i.second] = max(up[i.second],dep[i.second] - dep[l]); } dfs2(pos,0); } } }

Compilation message (stderr)

pipes.cpp: In function 'int main()':
pipes.cpp:109:20: error: no match for 'operator<' (operand types are 'int' and 'std::vector<std::pair<int, int> >::iterator {aka __gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >}')
            while(p < bri.end() && disj1.find(bri[p].first) != pos){
                  ~~^~~~~~~~~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/7/vector:60,
                 from pipes.cpp:2:
/usr/include/c++/7/bits/stl_pair.h:449:5: note: candidate: template<class _T1, class _T2> constexpr bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
     operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
     ^~~~~~~~
/usr/include/c++/7/bits/stl_pair.h:449:5: note:   template argument deduction/substitution failed:
pipes.cpp:109:30: note:   mismatched types 'const std::pair<_T1, _T2>' and 'int'
            while(p < bri.end() && disj1.find(bri[p].first) != pos){
                              ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/7/vector:60,
                 from pipes.cpp:2:
/usr/include/c++/7/bits/stl_iterator.h:305:5: note: candidate: template<class _Iterator> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
     operator<(const reverse_iterator<_Iterator>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:305:5: note:   template argument deduction/substitution failed:
pipes.cpp:109:30: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
            while(p < bri.end() && disj1.find(bri[p].first) != pos){
                              ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/7/vector:60,
                 from pipes.cpp:2:
/usr/include/c++/7/bits/stl_iterator.h:343:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
     operator<(const reverse_iterator<_IteratorL>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:343:5: note:   template argument deduction/substitution failed:
pipes.cpp:109:30: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
            while(p < bri.end() && disj1.find(bri[p].first) != pos){
                              ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/7/vector:60,
                 from pipes.cpp:2:
/usr/include/c++/7/bits/stl_iterator.h:1142:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)
     operator<(const move_iterator<_IteratorL>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:1142:5: note:   template argument deduction/substitution failed:
pipes.cpp:109:30: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'int'
            while(p < bri.end() && disj1.find(bri[p].first) != pos){
                              ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/7/vector:60,
                 from pipes.cpp:2:
/usr/include/c++/7/bits/stl_iterator.h:1148:5: note: candidate: template<class _Iterator> bool std::operator<(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)
     operator<(const move_iterator<_Iterator>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:1148:5: note:   template argument deduction/substitution failed:
pipes.cpp:109:30: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'int'
            while(p < bri.end() && disj1.find(bri[p].first) != pos){
                              ^
In file included from /usr/include/c++/7/vector:64:0,
                 from pipes.cpp:2:
/usr/include/c++/7/bits/stl_vector.h:1613:5: note: candidate: template<class _Tp, class _Alloc> bool std::operator<(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
     operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
     ^~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:1613:5: note:   template argument deduction/substitution failed:
pipes.cpp:109:30: note:   mismatched types 'const std::vector<_Tp, _Alloc>' and 'int'
            while(p < bri.end() && disj1.find(bri[p].first) != pos){
                              ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/7/vector:60,
                 from pipes.cpp:2:
/usr/include/c++/7/bits/stl_iterator.h:895:5: note: candidate: template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)
     operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:895:5: note:   template argument deduction/substitution failed:
pipes.cpp:109:30: note:   mismatched types 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>' and 'int'
            while(p < bri.end() && disj1.find(bri[p].first) != pos){
                              ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/7/vector:60,
                 from pipes.cpp:2:
/usr/include/c++/7/bits/stl_iterator.h:888:5: note: candidate: template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)
     operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:888:5: note:   template argument deduction/substitution failed:
pipes.cpp:109:30: note:   mismatched types 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>' and 'int'
            while(p < bri.end() && disj1.find(bri[p].first) != pos){
                              ^
pipes.cpp:72:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d\n",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:78:14: warning: ignoring return value of 'char* fgets(char*, int, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         fgets(str,15,stdin);
         ~~~~~^~~~~~~~~~~~~~