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>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

typedef tuple<int,int,int> edge;
int n,m;
vector<edge> graph;

const int nmax=510;
int par[nmax];
void init(){rep(i,nmax) par[i]=i;}
int find(int x){return (par[x]==x)?x:par[x]=find(par[x]);}
void unite(int a,int b){ a=find(a),b=find(b),par[a]=b;}
bool same(int a,int b){return find(a)==find(b);}

bool used[50010];

int main(void){
	cin >> n >> m;
	rep(i,m){
		int a,b,c;
		cin >> a >> b >> c;
		graph.push_back(edge(c,a,b));
	}
	sort(graph.begin(),graph.end());

	int mst=0;
	init();
	rep(i,m){
		int c,a,b;
		tie(c,a,b)=graph[i];
		if(same(a,b)) continue;
		used[i]=true;
		unite(a,b);
		mst+=c;
	}

	int num=0,sum=0;
	rep(i,m){
		if(!used[i]) continue;
		init();
		int cur=0;
		rep(j,m){
			if(j==i) continue;
			int c,a,b;
			tie(c,a,b)=graph[j];
			if(same(a,b)) continue;
			unite(a,b);
			cur+=c;
		}
		if(cur!=mst) num++,sum+=get<0>(graph[i]);
	}
	cout << num << " " << sum << endl;
	return 0;
}