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;
using vi=vector<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()

struct UnionFind{
	vi p;
	UnionFind(int s):p(s,-1){}
	void unite(int a,int b){
		a=root(a);b=root(b);
		if(a!=b){
			if(p[b]<p[a])swap(a,b);
			p[a]+=p[b];p[b]=a;
		}
	}
	bool same(int a,int b){return root(a)==root(b);}
	int root(int a){return p[a]<0?a:p[a]=root(p[a]);}
};

using data=tuple<int,int,int>;
int n,m;
vector<data> edge;
set<int> use;

int makeMST(int except=-1){
	int ret=0;
	UnionFind uf(n);
	rep(i,m){
		if(i==except) continue;
		int c,s,d; tie(c,s,d)=edge[i];
		if(!uf.same(s,d)){
			uf.unite(s,d);
			ret+=c;
			if(except==-1) use.insert(i);
		}
	}
	return ret;
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	cin>>n>>m;
		
	rep(i,m){
		int s,d,c; cin>>s>>d>>c;
		edge.emplace_back(c,s-1,d-1);
	}
	sort(all(edge),[](data a,data b){return get<0>(a)<get<0>(b);});

	int target=makeMST(),value=0,index=0;
	for(auto u:use){
		if(target!=makeMST(u)){
			index++;
			value+=get<0>(edge[u]);
		}
	}
	cout<<index<<" "<<value<<endl;
	return 0;
}