fork download
  1. #include <cstdio>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. #define edge pair< int, int >
  7. #define MAX 2001
  8.  
  9. // ( w (u, v) ) format
  10. vector< pair< int, edge > > GRAPH;
  11. vector<int> index;
  12. int parent[MAX], total, N, E;
  13.  
  14. int findset(int x, int *parent)
  15. {
  16. if(x != parent[x])
  17. parent[x] = findset(parent[x], parent);
  18. return parent[x];
  19. }
  20.  
  21. void kruskal()
  22. {
  23. int i, pu, pv;
  24. sort(GRAPH.begin(), GRAPH.end()); // increasing weight
  25. for(i=total=0; i<E; i++)
  26. {
  27. pu = findset(GRAPH[i].second.first, parent);
  28. pv = findset(GRAPH[i].second.second, parent);
  29. if(pu != pv)
  30. {
  31. index.push_back(i);
  32. parent[pu] = parent[pv]; // link
  33. total += GRAPH[i].first;
  34. }
  35. }
  36. }
  37.  
  38. int min;
  39. void second_MST()
  40. {
  41. min = 0;
  42. for (int i = 0; i < index.size(); i++)
  43. {
  44. total = 0;
  45. fill(parent, parent+MAX, 0);
  46. pair<int, edge> tmp(GRAPH[index[i]]);
  47. GRAPH.erase(GRAPH.begin()+i);
  48. kruskal();
  49. if (total == 0 || total < min) min = total;
  50. GRAPH.insert(GRAPH.begin()+i);
  51. }
  52. }
  53.  
  54. int main()
  55. {
  56. int i, u, v, w;
  57.  
  58. scanf("%d %d", &N, &E);
  59. for(int i=1; i<=N; i++) parent[i] = i;
  60. for(i=0; i<E; i++)
  61. {
  62. scanf("%d %d %d", &u, &v, &w);
  63. GRAPH.push_back(pair< int, edge >(w, edge(u, v)));
  64. }
  65. kruskal(); // runs kruskal and construct MST vector
  66. second_MST();
  67. printf("%d\n", min);
  68.  
  69. return 0;
  70. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
5 7
1 2 3
2 3 4
1 4 7
2 4 11
2 5 9
5 4 5
3 5 8
compilation info
prog.cpp:41:2: error: reference to 'min' is ambiguous
        min = 0;
        ^
prog.cpp:38:5: note: candidate found by name lookup is 'min'
int min;
    ^
/usr/bin/../lib/gcc/i586-linux-gnu/4.9/../../../../include/c++/4.9/bits/algorithmfwd.h:371:5: note: candidate found by name lookup is 'std::min'
    min(const _Tp&, const _Tp&, _Compare);
    ^
/usr/bin/../lib/gcc/i586-linux-gnu/4.9/../../../../include/c++/4.9/bits/algorithmfwd.h:367:5: note: candidate found by name lookup is 'std::min'
    min(const _Tp&, const _Tp&);
    ^
prog.cpp:49:29: error: reference to 'min' is ambiguous
                if (total == 0 || total < min) min = total;
                                          ^
prog.cpp:38:5: note: candidate found by name lookup is 'min'
int min;
    ^
/usr/bin/../lib/gcc/i586-linux-gnu/4.9/../../../../include/c++/4.9/bits/algorithmfwd.h:371:5: note: candidate found by name lookup is 'std::min'
    min(const _Tp&, const _Tp&, _Compare);
    ^
/usr/bin/../lib/gcc/i586-linux-gnu/4.9/../../../../include/c++/4.9/bits/algorithmfwd.h:367:5: note: candidate found by name lookup is 'std::min'
    min(const _Tp&, const _Tp&);
    ^
prog.cpp:49:34: error: reference to 'min' is ambiguous
                if (total == 0 || total < min) min = total;
                                               ^
prog.cpp:38:5: note: candidate found by name lookup is 'min'
int min;
    ^
/usr/bin/../lib/gcc/i586-linux-gnu/4.9/../../../../include/c++/4.9/bits/algorithmfwd.h:371:5: note: candidate found by name lookup is 'std::min'
    min(const _Tp&, const _Tp&, _Compare);
    ^
/usr/bin/../lib/gcc/i586-linux-gnu/4.9/../../../../include/c++/4.9/bits/algorithmfwd.h:367:5: note: candidate found by name lookup is 'std::min'
    min(const _Tp&, const _Tp&);
    ^
prog.cpp:50:9: error: no matching member function for call to 'insert'
                GRAPH.insert(GRAPH.begin()+i);
                ~~~~~~^~~~~~
/usr/bin/../lib/gcc/i586-linux-gnu/4.9/../../../../include/c++/4.9/bits/stl_vector.h:1120:9: note: candidate function template not viable: requires 3 arguments, but 1 was provided
        insert(iterator __position, _InputIterator __first,
        ^
/usr/bin/../lib/gcc/i586-linux-gnu/4.9/../../../../include/c++/4.9/bits/stl_vector.h:998:7: note: candidate function not viable: requires 2 arguments, but 1 was provided
      insert(iterator __position, const value_type& __x);
      ^
/usr/bin/../lib/gcc/i586-linux-gnu/4.9/../../../../include/c++/4.9/bits/stl_vector.h:1072:7: note: candidate function not viable: requires 3 arguments, but 1 was provided
      insert(iterator __position, size_type __n, const value_type& __x)
      ^
prog.cpp:67:20: error: reference to 'min' is ambiguous
    printf("%d\n", min);
                   ^
prog.cpp:38:5: note: candidate found by name lookup is 'min'
int min;
    ^
/usr/bin/../lib/gcc/i586-linux-gnu/4.9/../../../../include/c++/4.9/bits/algorithmfwd.h:371:5: note: candidate found by name lookup is 'std::min'
    min(const _Tp&, const _Tp&, _Compare);
    ^
/usr/bin/../lib/gcc/i586-linux-gnu/4.9/../../../../include/c++/4.9/bits/algorithmfwd.h:367:5: note: candidate found by name lookup is 'std::min'
    min(const _Tp&, const _Tp&);
    ^
5 errors generated.
stdout
Standard output is empty