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;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
template<typename T>
struct edge {
    int src, to;
    T cost;
};
template<typename T>
bool operator< (const edge<T> &e1, const edge<T> &e2) {
  return e1.cost < e2.cost;
}
template<typename T>
bool operator== (const edge<T> &e1, const edge<T> &e2) {
  return e1.src == e2.src && e1.to == e2.to && e1.cost == e2.cost;
}
struct UnionFind
{
    vector<int> par, sz;
    UnionFind(int n) : par(n), sz(n, 1) {
        for (int i = 0; i < n; ++i) par[i] = i;
    }
    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    void merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (sz[x] < sz[y]) swap(x, y);
        par[y] = x;
        sz[x] += sz[y];
        sz[y] = 0;
    }
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    int size(int x) {
        return sz[root(x)];
    }
};
template<typename T>
T kruskal(vector<edge<T>> &es, int V, vector<edge<T>> &tr) {
    UnionFind uf(V);
    T ret = 0;
    for (auto &e : es) {
        if (!uf.issame(e.src, e.to)) {
            ret += e.cost;
            tr.push_back(e);
            uf.merge(e.src, e.to);
        }
    }
    return ret;
}
template<typename T>
using Graph = vector<vector<edge<T>>>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n, m; cin >> n >> m;
  vector<edge<int>> edges, edges2;
  for(int i=0;i<m;++i) {
    int s, d, c; cin >> s >> d >> c;
    s--; d--;
    edges.push_back({s, d, c});
  }
  sort(edges.begin(), edges.end());
  vector<edge<int>> tr1;
  int w = kruskal(edges, n, tr1);
  int cnt = 0;
  int su = 0;
  for(auto &e: tr1) {
    auto it = find(edges.begin(), edges.end(), e);
    edges.erase(it);
    vector<edge<int>> tr2;
    int w2 = kruskal(edges, n, tr2);
    if(w != w2) {
      cnt++;
      su += e.cost;
    }
    edges.insert(it, e);
  }
  cout << cnt << " " << su << endl;;
}