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 FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int par[505];
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;
	if (par[x] < par[y]) swap(x, y);
	if (par[x] == par[y]) par[x]--;
	par[y] = x;
}

bool same(int x, int y)
{
	return find(x) == find(y);
}

int main()
{
	int n, m;
	cin >> n >> m;
	vector<edge> es;
	MS(par, -1);
	REP(i, m)
	{
		int a, b, c;
		cin >> a >> b >> c;
		es.push_back(edge{ a, b, c });
	}
	sort(ALL(es));
	vector<edge> used; 
	int sum = 0;
	REP(i, es.size())
	{
		if (!same(es[i].from, es[i].to))
		{
			unite(es[i].from, es[i].to);
			sum += es[i].cost;
			used.push_back(es[i]);
		}
	}
	
	int ans1 = 0, ans2 = 0;
	REP(j, used.size())
	{
		int sum_ = 0;
		MS(par, -1);
		REP(i, es.size())
		{
			if (es[i].from == used[j].from && es[i].to == used[j].to) continue;
			if (!same(es[i].from, es[i].to))
			{
				unite(es[i].from, es[i].to);
				sum_ += es[i].cost;
			}
		}
		if (sum == sum_)
		{
			ans1++;
			ans2 += used[j].cost;
		}
	}
	cout << n - ans1 - 1 << " " << sum - ans2 << endl;

	return 0;
}