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(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 505
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
struct edge{ int s,t,c; } in[M*100];
int n,m,fa[M];
vector<int> id;

int find(int x)
{
	return fa[x]==x ? x : fa[x] = find(fa[x]);
}
int work(int ban)
{
	int re=0;
	REP(i,1,n) fa[i]=i;
	
	REP(i,1,m) if(i != ban)
	{
		if( find(in[i].s) != find(in[i].t) )
		{
			if(ban==-1) id.PB(i);
			re += in[i].c;
			fa[find(in[i].s)] = find(in[i].t);
		}
	}
	return re;
}
int main()
{
	RI(n,m);
	REP(i,1,m) RI(in[i].s, in[i].t, in[i].c);
	sort(in+1, in+m+1, [](edge a, edge b) { return a.c < b.c; } );

	id.clear();
	int mst = work(-1);
	int a1=0, a2=0;
	FOR(i,id)
	{
		if( work(*i)!=mst )
		{
			a1 ++;
			a2 += in[*i].c;
		}
	}

	printf("%d %d\n",a1,a2);
	return 0;
}