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<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<utility>
#include<random>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-2;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

struct edge { int to, cost, id; };
bool exi[50000];
int cc[50000];

struct edge2 {
	int fr, to, cost;
	bool operator<(const edge2 &e)const {
		if (e.cost != cost)return cost < e.cost;
		if (e.fr != fr)return fr < e.fr;
		return to < e.to;
	}
};
vector<edge2> w;

vector<edge> G[500];
bool dfs(int id, int fr, int cost,int goal) {
	if (id == goal)return true;
	rep(j, G[id].size()) {
		int to = G[id][j].to;
		if (to == fr)continue;
		if (dfs(to, id, cost, goal)) {
			if (cost == G[id][j].cost) {
				exi[G[id][j].id] = false;
			}
			return true;
		}
	}
	return false;
}
int main() {
	int n, m; cin >> n >> m;
	w.resize(m);
	rep(i, m) {
		cin >> w[i].fr >> w[i].to >> w[i].cost;
		w[i].fr--; w[i].to--;
	}
	sort(w.begin(), w.end());
	rep(i, m) {
		int s = w[i].fr, t = w[i].to, c = w[i].cost;
		//cout << i << " " << s << " " << t << endl;
		cc[i] = c;
		if (!dfs(s,-1,c, t)) {
			exi[i] = true;
			G[s].push_back({ t,c,i });
			G[t].push_back({ s,c,i });
		}
	}
	int cnt = 0; int sum = 0;
	rep(i, m) {
		if (exi[i]) {
			cnt++; sum += w[i].cost;
			//cout << i << endl;
		}
	}
	cout << cnt << " " << sum << endl;
	//stop
	return 0;
}