Problem: Example

Input

4 4
1 2 3
1 3 3
2 3 3
2 4 3


Output

1 3

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

class UnionFind {
public:
  vector<int> par, rank; // parent(negative := its root and abs-value is its size), depth
  UnionFind(int sz) : par(sz, -1), rank(sz, 0){}
  int find(int x){
    if(par[x]<0) return x;
    else return par[x] = find(par[x]);
  }
  void unite(int x, int y){
    x=find(x); y=find(y);
    if(x==y) return;  // already belong to same tree
    if(rank[x] < rank[y]){  // y becomes parent node
      par[y] += par[x];
      par[x] = y;
    } else {  // x becomes parent node
      par[x] += par[y];
      par[y] = x;
      if(rank[x]==rank[y]) rank[x]++;
    }
  }
  bool same(int x, int y){ return find(x) == find(y); }
  int size(int x){ return -par[find(x)]; }
};

int main(){
  int n,m;
  cin>>n>>m;
  using P = pair<pair<long,int>,pair<int,int>>;
  // cost, id, s, t
  vector<P> vec(m);
  vector<long> costs(m);
  rep(i,m){
    int s,d,c;
    cin>>s>>d>>c;
    s--;d--;
    vec[i] = P{{c,i},{s,d}};
    costs[i] = c;
  }

  sort(all(vec));

  vector<bool> used(m,false);

  auto mst = [&](int nouse){
    UnionFind uf(n);
    long ret = 0;
    for(auto p : vec){
      int s = p.se.fi, t = p.se.se;
      if(uf.same(s,t)) continue;
      if(p.fi.se == nouse) continue;
      uf.unite(s,t);
      ret += p.fi.fi;
      used[p.fi.se] = true;
    }
    if(uf.size(0)!=n) return 123456789456789L;
    return ret;
  };

  vector<int> cand;
  int cost = mst(-1);

  rep(i,m) if(used[i]) cand.pb(i);

  int a = 0; long b = 0;
  for(auto i : cand){
    long r = mst(i);
    if(r>cost){
      a++;
      b += costs[i];
    }
  }
  cout << a << " " << b << endl;

  return 0;
}