Problem: E: Balanced Edge Deletion

problem

Given a weighted simple undirected graph G of N vertices and M edges. The vertices are numbered from 1 to N and the edges are numbered from 1 to M. The i-th edge connects the vertices u_i and v_i, and its cost is w_i.

Consider performing the following operation only once for this graph.

* Select one edge from the set of edges in G and delete that edge.



Since the graph may be divided by the above operation, the graph after the operation will be referred to as A and B. (If not split, B is an empty graph.) Let W (X) be the sum of the costs of the edges in graph X (W (X) = 0 if there are no edges in the graph) and $ \ mathrm Define {cost} $ (A, B) = | W (A) −W (B) |. Find the edge (u, v) that minimizes $ \ mathrm {cost} $ (A, B). If there are more than one, answer the one with the smallest u. If there are still more than one, answer the one with the smallest v.

Input format

The input is given in the following format:


N M
u_1 v_1 w_1
...
u_M v_M w_M


Constraint

* 2 \ leq N \ leq 10 ^ 5
* 1 \ leq M \ leq 10 ^ 5
* 1 \ leq u_i <v_i \ leq N
* If i \ neq j, u_i \ neq u_j or v_i \ neq v_j
* 1 \ leq w_i \ leq 10 ^ 9



The graph given is concatenated.

Output format

Output the answer side to one line separated by blanks as shown below.


u v

* u, v are integers
* 1 \ leq u, v \ leq N



Input example 1


5 4
1 2 1
2 3 10
3 4 5
4 5 1


Output example 1


twenty three

Input example 2


10 11
1 2 1
2 3 10
1 5 2
3 4 7
3 5 9
5 6 8
6 7 5
6 8 3
7 8 12
7 9 1
9 10 8


Output example 2


5 6





Example

Input

5 4
1 2 1
2 3 10
3 4 5
4 5 1


Output

2 3

Solution (in CPP):

Solution:
#include<bits/stdc++.h>

using namespace std;
typedef long long LL;

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r) { bool a = l>r; if (a)l = r; return a; }
template <typename T>inline bool chmax(T &l, T r) { bool a = l<r; if (a)l = r; return a; }

int N, M;
int a[112345];
int b[112345];
LL c[112345];

int dep[112345];
int used[112345];
int br[112345];
int imos[112345];
using V = vector<int>;
using VV = vector<V>;
VV g;
void latte(int v,int pe,int d) {
	dep[v] = d;
	used[v] = 1;
	for (int e : g[v]) {
		if (e == pe)continue;
		int u = a[e] ^ b[e] ^ v;
		if(used[u]==0)latte(u, e, d + 1);
	}
}
void malta(int v, int pe) {
	used[v] = 1;
	for (int e : g[v]) {
		if (e == pe)continue;
		int u = a[e] ^ b[e] ^ v;
		if (used[u] == 1) {
			if (dep[u] < dep[v]) {
				imos[v]++;
				imos[u]--;
			}
		}
		else {
			malta(u, e);
			imos[v] += imos[u];
		}
	}
	if (imos[v]==0)br[pe] = 1;
}
using T = tuple<LL, int, int>;
T ans(0, 0, 0);
LL sum = 0;

LL sub[112345];
void beet(int v, int pe) {
	used[v] = 1;
	sub[v] = 0;
	for (int e : g[v]) {
		sub[v] += c[e];
		if (e == pe)continue;
		int u = a[e] ^ b[e] ^ v;
		if (used[u] == 0) {
			beet(u, e);
			sub[v] += sub[u];
			if (br[e]) {
				LL A = (sub[u] - c[e]) / 2;
				LL B = sum - A - c[e];
				//cout << abs(A - B) << " " << a[e] + 1 << " " << b[e] + 1 << endl;
				chmin(ans, T(abs(A - B), a[e] + 1, b[e] + 1));
			}

		}
	}
}
constexpr int NG = 112340;
int main() {
	cin >> N >> M;
	g = VV(N);
	REP(i, M) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--;
		g[a[i]].push_back(i);
		g[b[i]].push_back(i);
		sum += c[i];
	}
	ans = T(sum, 0, 0);
	REP(i, N)used[i] = 0;
	latte(0, NG, 0);
	REP(i, M)br[i] = 0;
	REP(i, N)used[i] = 0;
	REP(i, N)imos[i] = 0;
	malta(0, NG);
	REP(i, M) {
		if (br[i] == 0)chmin(ans, T(sum - c[i], a[i] + 1, b[i] + 1));
	}
	REP(i, N)used[i] = 0;
	beet(0, NG);
	LL x;
	int y, z;
	tie(x, y, z) = ans;
	cout << y << " " << z << endl;
	return 0;
}