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;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

struct UnionFind {
  vector<int> par, rank, sz;
  UnionFind(int n) {
    par.assign(n, 0);
    rank.assign(n, 0);
    sz.assign(n, 1);
    for (int i = 0; i < n; i++) { par[i] = i; }
  }
  int find(int x) {
    if (par[x] == x)
      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;
    if (rank[x] < rank[y]) {
      par[x] = y;
      sz[y] += sz[x];
    } else {
      par[y] = x;
      sz[x] += sz[y];
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
};

struct Edge {
  int from, to, cost;
  Edge() {}
  Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
  bool operator<(const Edge a) const { return cost < a.cost; }
};

void solve() {
  int N, M;
  cin >> N >> M;
  vector<Edge> es;
  for (int i = 0; i < M; i++) {
    int s, d, c;
    cin >> s >> d >> c;
    s--;
    d--;
    es.emplace_back(s, d, c);
  }
  sort(all(es));
  vector<Edge> tree;
  int min_cost = 0;
  {
    UnionFind uf(N);
    for (int i = 0; i < M; i++) {
      Edge &e = es[i];
      if (!uf.same(e.to, e.from)) {
        uf.unite(e.to, e.from);
        tree.push_back(e);
        min_cost += e.cost;
      }
    }
  }
  // dmp(min_cost);
  int ans = 0;
  int ans_cost = 0;
  for (const Edge &cand : tree) {
    UnionFind uf(N);
    int sum_cost = 0;
    int cnt = 0;
    for (const Edge &e : es) {
      if (e.to == cand.to && e.from == cand.from) continue;
      if (!uf.same(e.to, e.from)) {
        uf.unite(e.to, e.from);
        sum_cost += e.cost;
        cnt++;
      }
    }
    if (sum_cost > min_cost || cnt < N - 1) {
      ans++;
      ans_cost += cand.cost;
    }
  }
  cout << ans << ' ' << ans_cost << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}