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
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <bitset>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

struct UnionFind {
	vector<int> data;
	void init(int n) { data.assign(n, -1); }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if(x != y) {
			if(data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) { return root(x) == root(y); }
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
	int size(int x) { return -data[root(x)]; }
};

typedef int Weight;
struct Edge {
	int x, y;
	Weight w;
	Edge() { }
	Edge(int x_, int y_, Weight w_): x(x_), y(y_), w(w_) { }
};
bool operator<(const Edge &a, const Edge &b) { return a.w < b.w; }


int main() {
	int N, M;
	scanf("%d%d", &N, &M);
	vector<Edge> edges(M);
	rep(i, M) {
		int S, D, C;
		scanf("%d%d%d", &S, &D, &C), -- S, -- D;
		edges[i] = Edge(S, D, C);
	}
	sort(all(edges));
	vector<int> mst;
	{	UnionFind uf; uf.init(N);
		rep(i, edges.size()) {
			Edge e = edges[i];
			if(uf.unionSet(e.x, e.y))
				mst.push_back(i);
		}
	}
	int cnt = 0, sum = 0;
	rep(ix, mst.size()) {
		UnionFind uf; uf.init(N);
		int i = mst[ix];
		rep(jx, mst.size()) if(ix != jx)
			uf.unionSet(edges[mst[jx]].x, edges[mst[jx]].y);
		bool important = true;
		int w = edges[i].w;
		rep(j, edges.size()) if(j != i) {
			if(w == edges[j].w && !uf.findSet(edges[j].x, edges[j].y)) {
				important = false;
			}
		}
		if(important) {
			++ cnt;
			sum += w;
		}
	}
	printf("%d %d\n", cnt, sum);
	return 0;
}