Problem: After a successful field test, Heidi is considering deploying a trap along some Corridor, possibly not the first one. She wants to avoid meeting the Daleks inside the Time Vortex, so for abundance of caution she considers placing the traps only along those Corridors that are not going to be used according to the current Daleks' plan – which is to use a minimum spanning tree of Corridors. Heidi knows that all energy requirements for different Corridors are now different, and that the Daleks have a single unique plan which they are intending to use.

Your task is to calculate the number E_{max}(c), which is defined in the same way as in the easy version – i.e., the largest e ≤ 10^9 such that if we changed the energy of corridor c to e, the Daleks might use it – but now for every corridor that Heidi considers. 

Input

The first line: number n of destinations, number m of Time Corridors (2 ≤ n ≤ 10^5, n - 1 ≤ m ≤ 10^6). The next m lines: destinations a, b and energy e (1 ≤ a, b ≤ n, a ≠ b, 0 ≤ e ≤ 10^9).

No pair \\{a, b\} will repeat. The graph is guaranteed to be connected. All energy requirements e are distinct.

Output

Output m-(n-1) lines, each containing one integer: E_{max}(c_i) for the i-th Corridor c_i from the input that is not part of the current Daleks' plan (minimum spanning tree).

Example

Input

3 3
1 2 8
2 3 3
3 1 4


Output

4

Note

If m = n-1, then you need not output anything.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, pair<int, int> > > pq;
unordered_set<int> us;
queue<int> q;
vector<pair<int, int> > graf[100005], legit[100005];
int tata[100005], sz[100005], n, m, nivel[1000005], euclid[1000005], cnt,
    fr[100005], rmq[1000005][22], loga[1000005], put[1000005], nex[100005][22],
    str[100005][22];
long long cost;
pair<int, pair<int, int> > v[1000005];
void unite(int a, int b, int c) {
  int cp = a;
  while (cp != tata[cp]) {
    cp = tata[cp];
  }
  int cp1 = a;
  while (cp1 != cp) {
    int aux = tata[cp1];
    tata[cp1] = cp;
    cp1 = aux;
  }
  cp = b;
  cp1 = b;
  while (cp != tata[cp]) {
    cp = tata[cp];
  }
  while (cp1 != cp) {
    int aux = tata[cp1];
    tata[cp1] = cp;
    cp1 = aux;
  }
  if (tata[a] == tata[b]) {
    return;
  } else if (sz[tata[a]] > sz[tata[b]]) {
    tata[tata[b]] = tata[a];
    sz[tata[a]] += sz[tata[b]];
  } else {
    tata[tata[a]] = tata[b];
    sz[tata[b]] += sz[tata[a]];
  }
  cost += c;
  graf[a].push_back(make_pair(b, c));
  graf[b].push_back(make_pair(a, c));
}
void dfs(int nod, int niv) {
  nivel[++cnt] = niv;
  euclid[cnt] = nod;
  if (fr[nod] == 0) {
    fr[nod] = cnt;
  }
  for (int i = 0; i < legit[nod].size(); i++) {
    dfs(legit[nod][i].first, niv + 1);
    nivel[++cnt] = niv;
    euclid[cnt] = nod;
  }
}
int find_lca(int a, int b) {
  int st = fr[a], dr = fr[b];
  if (st > dr) swap(st, dr);
  int dist = dr - st + 1;
  if (nivel[rmq[st][loga[dist]]] <
      nivel[rmq[dr - put[loga[dist]] + 1][loga[dist]]]) {
    return euclid[rmq[st][loga[dist]]];
  }
  return euclid[rmq[dr - put[loga[dist]] + 1][loga[dist]]];
}
long long mi(long long a, long long b) {
  if (a > b) return b;
  return a;
}
long long ma(long long a, long long b) {
  if (a > b) return a;
  return b;
}
long long find_max(int down, int up) {
  if (nivel[fr[down]] < nivel[fr[up]]) swap(up, down);
  int dist = nivel[fr[down]] - nivel[fr[up]], maxim = 0;
  while (dist != 0) {
    int e = loga[dist];
    maxim = ma(str[down][e], maxim);
    down = nex[down][e];
    dist -= put[e];
  }
  return maxim;
}
bool exista(int ind) {
  int a = v[ind].first, b = v[ind].second.first;
  for (int i = 0; i < legit[a].size(); i++)
    if (legit[a][i].first == b) return true;
  swap(a, b);
  for (int i = 0; i < legit[a].size(); i++)
    if (legit[a][i].first == b) return true;
  return false;
}
int main() {
  int a, b, c;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> v[i].first >> v[i].second.first >> v[i].second.second;
    a = v[i].first;
    b = v[i].second.first;
    c = v[i].second.second;
    pq.push(make_pair(-c, make_pair(a, b)));
  }
  for (int i = 1; i <= n; i++) tata[i] = i;
  for (int i = 1; i <= n; i++) sz[i] = 1;
  while (pq.empty() == false) {
    pair<int, pair<int, int> > x = pq.top();
    pq.pop();
    unite(x.second.first, x.second.second, -x.first);
  }
  q.push(1);
  us.insert(1);
  while (q.empty() == false) {
    int nod = q.front();
    q.pop();
    for (int i = 0; i < graf[nod].size(); i++) {
      if (us.count(graf[nod][i].first) == 0) {
        legit[nod].push_back(graf[nod][i]);
        us.insert(graf[nod][i].first);
        q.push(graf[nod][i].first);
      }
    }
    graf[nod].clear();
  }
  dfs(1, 1);
  for (int i = 1; i <= cnt; i++) {
    rmq[i][0] = i;
  }
  put[0] = 1;
  for (int i = 1; i <= 25; i++) {
    put[i] = put[i - 1] * 2;
    if (put[i] <= cnt) loga[put[i]] = 1;
  }
  for (int i = 1; i <= cnt; i++) {
    loga[i] += loga[i - 1];
  }
  for (int j = 1; j <= 20; j++) {
    for (int i = 1; i <= cnt; i++) {
      if (nivel[rmq[i][j - 1]] < nivel[rmq[i + put[j - 1]][j - 1]]) {
        rmq[i][j] = rmq[i][j - 1];
      } else
        rmq[i][j] = rmq[i + put[j - 1]][j - 1];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < legit[i].size(); j++) {
      nex[legit[i][j].first][0] = i;
      str[legit[i][j].first][0] = legit[i][j].second;
    }
  }
  nex[1][0] = 1;
  for (int j = 1; j <= 20; j++) {
    for (int i = 1; i <= n; i++) {
      nex[i][j] = nex[nex[i][j - 1]][j - 1];
      str[i][j] = ma(str[i][j - 1], str[nex[i][j - 1]][j - 1]);
    }
  }
  for (int i = 1; i <= m; i++) {
    int a = v[i].first, b = v[i].second.first;
    int lca = find_lca(a, b);
    long long maxim = ma(find_max(a, lca), find_max(b, lca));
    if (exista(i) == false) {
      cout << maxim << "\n";
    }
  }
  return 0;
}