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;

struct edge{
  int from,to,cost;
  bool operator < (const edge &p)const{
   return cost < p.cost;
  }
};

int pa[1000],ra[1000];
void init(){
  for(int i=0;i<1000;i++){
    pa[i]=i;
    ra[i]=0;
  }
}

int find(int x){
  if(x==pa[x])return x;
  else return pa[x]=find(pa[x]);
}

bool same(int x,int y){
  return find(x)==find(y);
}

void unite(int x,int y){
  x=find(x),y=find(y);
  if(ra[x]<ra[y])swap(x,y);
  pa[y]=x;
  if(ra[x]==ra[y])ra[x]++;
}

int N,M;
int a,b,c;
int flg[100000];
vector<edge> t;

int solve(int id){
  int sum=0;
  for(int i=0;i<(int)t.size();i++){
    if(i==id)continue;
    edge e=t[i];
    if(same(e.from,e.to))continue;
    unite(e.from,e.to);
    sum+=e.cost;
    if(id==-1)flg[i]=true;
  }
  if(id!=-1){
    edge e=t[id];
    if(same(e.from,e.to))return sum;
    else return 1e9;
  }
  return sum;
}

int main(){
  cin>>N>>M;
  init();
  t.clear();
  for(int i=0;i<M;i++){
    scanf("%d %d %d",&a,&b,&c);
    t.push_back((edge){a,b,c});
  }
  sort(t.begin(),t.end());
  int base=solve(-1);  
  

  int ans=0,ans2=0;
  for(int i=0;i<M;i++){
    if(flg[i]==false)continue;
    init();
    int b=solve(i);

    if(base==b)continue;
    ans++;
    ans2+=t[i].cost;
  }
  cout<<ans<<' '<<ans2<<endl;
  return 0;
}