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
#include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


int N,M;
int A[222222];
int S[222222];

map<pint,int>uku;

vector<int> G[1000000];
vector<pair<int, int> > bridge;
vector<int> articulation;
int ord[1000000], low[1000000];
bool vis[1000000];

tuple<int,int,int>ans;
int sumall;

int X[222222],Y[222222],Z[222222];

void dfs(int v, int p, int &k)
{

    S[v]=A[v];
	vis[v] = true;

	ord[v] = k++;
	low[v] = ord[v];

	bool isArticulation = false;
	int ct = 0;

	for (int i = 0; i < G[v].size(); i++){
		if (!vis[G[v][i]]){
			ct++;
			dfs(G[v][i], v, k);
			S[v]+=S[G[v][i]];
			low[v] = min(low[v], low[G[v][i]]);
			if (~p && ord[v] <= low[G[v][i]]) isArticulation = true;
			if (ord[v] < low[G[v][i]]){
                int x=v;
                int y=G[v][i];
                int Sy=(S[y]-uku[minmax(x,y)])/2;
                int Sx=sumall-uku[minmax(x,y)]-Sy;
                if(x>y)swap(x,y);
                chmin(ans,make_tuple(abs(Sx-Sy),x,y));
            }
		}
		else if (G[v][i] != p){
			low[v] = min(low[v], ord[G[v][i]]);
		}
	}

	if (p == -1 && ct > 1) isArticulation = true;
	if (isArticulation) articulation.push_back(v);
}


signed main(){
    cin>>N>>M;
    ans=make_tuple(LLONG_MAX,-1,-1);
    rep(i,M){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        if(a>b)swap(a,b);



        X[i]=a;Y[i]=b;Z[i]=c;
        uku[{a,b}]=c;
        G[a].pb(b);G[b].pb(a);
        A[a]+=c;
        A[b]+=c;
        sumall+=c;
    }


    rep(i,M){
        chmin(ans,make_tuple(sumall-Z[i],X[i],Y[i]));
    }
    int K;
    dfs(0,-1,K);
    cout<<get<1>(ans)+1<<" "<<get<2>(ans)+1<<endl;
    return 0;
}

