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 <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1e18;

int n, m;

typedef struct edge_ {
		int from, to, cost;
		edge_(int f, int t, int c): from(f), to(t), cost(c){};
} edge;

int par[501];
int r[501];

void init(){
		for(int i = 0; i < n; i++){
				par[i] = i;
				r[i] = 0;
		}
}

int find(int x){
		if(par[x] == x)return x;
		else return par[x] = find(par[x]);
}

void unite(int x, int y){
		int xp = find(x);
		int yp = find(y);
		if(xp == yp)return;
		if(r[xp] < r[yp])par[xp] = yp;
		else {
				par[yp] = xp;
				if(r[xp] == r[yp])r[xp]++;
		}
}

bool comp(const edge &ed1, const edge &ed2){
		return ed1.cost < ed2.cost;
}

vector<edge> vec;
vector<edge> ansvec;

ll kruscal(edge e){
	init();
	ll ans = 0;
	for(auto itr = vec.begin(); itr != vec.end(); ++itr){
			int from = (*itr).from;
			int to = (*itr).to;
			int cost = (*itr).cost;
			if(from == e.from && to == e.to)continue;
			if(find(from) != find(to)){
					ans += cost;
					unite(from, to);
					if(e.from == -1)ansvec.pb((*itr));
			}
	}
	return ans;

}

int main(int argc, char const* argv[])
{
	cin >> n >> m;
	for(int i = 0; i < m; i++){
			int s, t, u;
			cin >> s >> t >> u;
			s--; t--;
			vec.pb(edge(s, t, u));
	}
	sort(vec.begin(), vec.end(), comp);
	ll ans = kruscal(edge(-1, -1, -1));
	int num = 0;
	ll costsum = 0;
	for(auto itr = ansvec.begin(); itr != ansvec.end(); ++itr){
			ll thisans = kruscal(*itr);
			if(thisans != ans){
					num++;
					costsum += (*itr).cost;
			}
	}
	cout << num << " " << costsum << endl;
	return 0;
}