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 ff first
#define ss second
typedef pair< int , pair< int, int > > piii;
int n, m;
int root[1000];
vector< piii > pq;
vector< int > vc;

int find_root(int n){
   if(n!=root[n]) return root[n]=find_root(root[n]);
   return n;
}

int kruskal(bool f, int dodge){
    int cnt=1;
    for(int i=1;i<=n;i++){
        root[i]=i;
    }

    int sum=0;
    for(int i=0;i<m;i++){
        if(i==dodge) continue;
        if(cnt==n) break;
        piii e = pq[i];
    	int px = find_root(e.ss.ff);
    	int py = find_root(e.ss.ss);
    	if(px!=py){
            root[px]=py;
            cnt++;
	        sum+=e.ff;
            if(f) vc.push_back(i);
    	}
    }

    if(cnt!=n) return -1;
    else return sum;
}


int main(){
	scanf("%d%d", &n, &m);
	for(int i=1;i<=m;i++){
		int u,v,c;
		scanf("%d%d%d", &u, &v, &c);
		pq.push_back({c,{u,v}});
	}
	sort(pq.begin(), pq.end());

	int cost = kruskal(1,-1),  ans=0, cnt=0;
	//cout<<cost<<" "<<vc.size()<<endl;
	for(int i=0;i<vc.size();i++){
		int tmp = kruskal(0,vc[i]);
		//cout<<i<<" "<<tmp<<endl;
		if(tmp!=cost){
			cnt++;
			ans+=pq[vc[i]].ff;
		}
	}

	printf("%d %d\n", cnt, ans);
	return 0;
}