Problem: Example

Input

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


Output

1 3

Solution (in CPP):

Solution:
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


#define int ll

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

int union_tree[600];
int union_find(int now) {
    if (union_tree[now] == now) return now;
    return union_tree[now] = union_find(union_tree[now]);
}
int union_merge(int a, int b) {
    a = union_find(a);
    b = union_find(b);
    if (a == b) return 0;
    union_tree[a] = b;
    return 1;
}

int color[60000];

void solve(){
    int n, m;
    cin >> n >> m;
    vector<tuple<int, int, int>> inputs;
    REP(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        inputs.push_back(make_tuple(c, a, b));
    }
    sort(ALL(inputs));
    REP(i, n) {
        union_tree[i] = i;
    }
    int ans = 0;
    REP(i, m) {
        color[i] = union_merge(get<1>(inputs[i]), get<2>(inputs[i]));
        ans += color[i] * get<0>(inputs[i]);
    }
    pair<int, int> go = mp(0, 0);
    REP(i, m) {
        if (color[i] == 0) continue;
        REP(q, n) {
            union_tree[q] = q;
        }
        int cnt = 0;
        REP(q, m) {
            if (i == q)continue;
            cnt += union_merge(get<1>(inputs[q]), get<2>(inputs[q])) * get<0>(inputs[q]);
        }
        int ok = 1;
        REP(q, n) {
            if (union_find(q) != union_find(0)) {
                ok = 0;
            }
        }
        if (ans != cnt || ok == 0) {
            go.first++;
            go.second += get<0>(inputs[i]);
        }
    }
    cout << go.first << " " << go.second << endl;
}

#undef int
int main() {
    init();
    solve();
}