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 maxn 50018
#define N 558
#define inf 200000000
#define PII pair<int,int>
using namespace std;
int n,m;
int cnt = 0;
int sum1,sum2;
int ans;
int father[N];
struct nod{
    int from,to,cost;
   
}edg[maxn];
bool cmp(nod i,nod j)
{
    return i.cost<j.cost;
}
int v[N],num[N];
void init()
{
    for(int i = 0;i <= n;i ++)
    {
        father[i]=i;num[i]=1;
    }
}
int find(int x){
    if(x!=father[x]) return father[x]=find(father[x]);
    return father[x];
}

bool Union(int x,int y)
{
        int fx = find(x),fy = find(y);
    if(fx!=fy)
    {
        father[fy] = fx;  num[fx]+=num[fy]; return true;
    }
    else
    {
        return false;
    }
         
}
void krus2()
{
    sum1=0,sum2=0;
    for(int i=0;i<cnt;i++){
       // cout << cnt << endl;
        int tmp=0;init();
        for(int j=0;j<m;j++){
            if(j!=v[i]){
                if(Union(edg[j].from,edg[j].to))
                {
                    tmp+=edg[j].cost;
                }
            
            }
        }
        if(tmp!=ans) sum1++,sum2+=edg[v[i]].cost;
    }
    printf("%d %d\n",sum1,sum2);
}
int main(){
     //freopen("in.txt","r",stdin);
    while(~scanf("%d%d",&n,&m)){
        cnt = 0;
        init();
        for(int i=0;i<m;i++){
            scanf("%d%d%d",&edg[i].from,&edg[i].to,&edg[i].cost);
        }
        sort(edg,edg+m,cmp);
        ans=0;
        memset(v,0,sizeof(v));
        for(int i=0;i<m;i++){
            if(Union(edg[i].from,edg[i].to)){
                ans+=edg[i].cost;
                v[cnt++]=i;
            }
        }
        krus2();
    }
    return 0;
}