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 dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

struct UnionFind{
	vi data;
	UnionFind(int n):data(n,-1){}
	int Find(int i){
		return data[i]<0?i:(data[i]=Find(data[i]));
	}
	bool Unite(int a,int b){
		a=Find(a),b=Find(b);
		if(a==b) return false;
		if(-data[a]<-data[b]) swap(a,b);
		data[a]+=data[b];
		data[b]=a;
		return true;
	}
	int Size(int i){
		return -data[Find(i)];
	}
};

struct Edge{
	int src,dst,weight;
	Edge(){}
	Edge(int s,int d,int w):src(s),dst(d),weight(w){}
};
typedef vector<vector<Edge>> Graph;
bool operator<(const Edge& a,const Edge& b){return a.weight<b.weight;}
bool operator>(const Edge& a,const Edge& b){return a.weight>b.weight;}

int Kruskal(int n,vector<Edge> es,vi& forest)
{
	UnionFind uf(n);
	int res=0;
	rep(i,es.size()){
		Edge e=es[i];
		if(uf.Unite(e.src,e.dst)){
			res+=e.weight;
			forest.push_back(i);
		}
	}
	return res;
}

int main()
{
	for(int n,m;cin>>n>>m && n|m;){
		vector<Edge> edges;
		rep(i,m){
			int u,v,w; cin>>u>>v>>w; u--,v--;
			edges.emplace_back(u,v,w);
		}
		sort(all(edges));
		
		vi cands;
		const int sum=Kruskal(n,edges,cands);
		
		int cnt=0,bsum=0;
		for(int ci:cands){
			Edge candidate=edges[ci];
			vector<Edge> backup=edges;
			edges[ci].weight=INF;
			sort(all(edges));
			
			int weight=0;
			UnionFind uf(n);
			for(Edge e:edges)
				if(uf.Unite(e.src,e.dst))
					weight+=e.weight;
			if(weight>sum){
				cnt++;
				bsum+=candidate.weight;
			}
			
			swap(edges,backup);
		}
		cout<<cnt<<' '<<bsum<<endl;
	}
}