#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
template <typename _T>
inline void read(_T &f) {
  f = 0;
  _T fu = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') fu = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    f = (f << 3) + (f << 1) + (c & 15);
    c = getchar();
  }
  f *= fu;
}
template <typename T>
void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x < 10)
    putchar(x + 48);
  else
    print(x / 10), putchar(x % 10 + 48);
}
template <typename T>
void print(T x, char t) {
  print(x);
  putchar(t);
}
template <typename T>
struct hash_map_t {
  vector<T> v, val, nxt;
  vector<int> head;
  int mod, tot, lastv;
  T lastans;
  bool have_ans;
  hash_map_t(int md = 0) {
    head.clear();
    v.clear();
    val.clear();
    nxt.clear();
    tot = 0;
    mod = md;
    nxt.resize(1);
    v.resize(1);
    val.resize(1);
    head.resize(mod);
    have_ans = 0;
  }
  void clear() { *this = hash_map_t(mod); }
  bool count(int x) {
    int u = x % mod;
    for (register int i = head[u]; i; i = nxt[i]) {
      if (v[i] == x) {
        have_ans = 1;
        lastv = x;
        lastans = val[i];
        return 1;
      }
    }
    return 0;
  }
  void ins(int x, int y) {
    int u = x % mod;
    nxt.push_back(head[u]);
    head[u] = ++tot;
    v.push_back(x);
    val.push_back(y);
  }
  int qry(int x) {
    if (have_ans && lastv == x) return lastans;
    count(x);
    return lastans;
  }
};
const int N = 1e5 + 5;
struct ele {
  int u, v, val, id, tag;
  bool operator<(const ele A) const { return val < A.val; }
} a[N * 10];
struct edge_t {
  int u, v, next, val, id;
} G[N << 1];
multiset<int> g[N];
multiset<int>::iterator it;
vector<int> del[N];
int ans[N * 10], f[N], head[N], maxn[N][20], fa[N][20], id[N], d[N], trueid[N],
    vis[N * 10];
int n, m, tot;
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
inline void addedge(int u, int v, int val, int id) {
  G[++tot] = (edge_t){u, v, head[u], val, id}, head[u] = tot;
  G[++tot] = (edge_t){v, u, head[v], val, id}, head[v] = tot;
}
void dfs1(int u, int f) {
  for (register int i = 1; i <= 19; i++) {
    fa[u][i] = fa[fa[u][i - 1]][i - 1];
    maxn[u][i] = max(maxn[u][i - 1], maxn[fa[u][i - 1]][i - 1]);
  }
  for (register int i = head[u]; i; i = G[i].next) {
    int v = G[i].v;
    if (v == f) continue;
    fa[v][0] = u;
    maxn[v][0] = G[i].val;
    id[v] = G[i].id;
    d[v] = d[u] + 1;
    dfs1(v, u);
  }
}
int lca(int u, int v) {
  if (d[u] < d[v]) swap(u, v);
  for (register int i = 19; i >= 0; i--) {
    if (d[fa[u][i]] >= d[v]) {
      u = fa[u][i];
    }
  }
  if (u == v) return u;
  for (register int i = 19; i >= 0; i--) {
    if (fa[u][i] != fa[v][i]) {
      u = fa[u][i];
      v = fa[v][i];
    }
  }
  return fa[u][0];
}
int query(int u, int v) {
  int ans = 0;
  if (d[u] < d[v]) swap(u, v);
  for (register int i = 19; i >= 0; i--) {
    if (d[fa[u][i]] >= d[v]) {
      ans = max(ans, maxn[u][i]);
      u = fa[u][i];
    }
  }
  if (u == v) return ans;
  for (register int i = 19; i >= 0; i--) {
    if (fa[u][i] != fa[v][i]) {
      ans = max(ans, max(maxn[u][i], maxn[v][i]));
      u = fa[u][i];
      v = fa[v][i];
    }
  }
  return max(ans, max(maxn[u][0], maxn[v][0]));
}
void dfs2(int u, int f) {
  trueid[u] = u;
  for (register int i = head[u]; i; i = G[i].next) {
    int v = G[i].v;
    if (v == f) continue;
    dfs2(v, u);
    if (g[trueid[v]].size() < g[trueid[u]].size()) {
      for (it = g[trueid[v]].begin(); it != g[trueid[v]].end(); ++it)
        g[trueid[u]].insert(*it);
      g[trueid[v]].clear();
    } else {
      for (it = g[trueid[u]].begin(); it != g[trueid[u]].end(); ++it)
        g[trueid[v]].insert(*it);
      g[trueid[u]].clear();
      trueid[u] = trueid[v];
    }
  }
  if (u == 1) return;
  for (register unsigned i = 0; i < del[u].size(); i++)
    g[trueid[u]].erase(g[trueid[u]].find(del[u][i]));
  if (g[trueid[u]].size() == 0)
    ans[id[u]] = 1e9;
  else
    ans[id[u]] = *g[trueid[u]].begin();
}
int main() {
  read(n);
  read(m);
  for (register int i = 1; i <= m; i++) {
    read(a[i].u);
    read(a[i].v);
    read(a[i].val);
    a[i].id = i;
  }
  sort(a + 1, a + m + 1);
  for (register int i = 1; i <= n; i++) f[i] = i;
  for (register int i = 1; i <= m; i++) {
    int x = find(a[i].u), y = find(a[i].v);
    if (x != y) {
      f[x] = y;
      a[i].tag = 1;
      vis[a[i].id] = 1;
      addedge(a[i].u, a[i].v, a[i].val, a[i].id);
    }
  }
  d[1] = 1;
  dfs1(1, 0);
  for (register int i = 1; i <= m; i++) {
    if (a[i].tag == 0) {
      ans[a[i].id] = query(a[i].u, a[i].v);
      int d = lca(a[i].u, a[i].v);
      g[a[i].u].insert(a[i].val);
      g[a[i].v].insert(a[i].val);
      del[d].push_back(a[i].val);
      del[d].push_back(a[i].val);
    }
  }
  dfs2(1, 0);
  for (register int i = 1; i <= m; i++)
    if (vis[i] == 0) print(ans[i], '\n');
  return 0;
}

### Prompt

Construct a Cpp code solution to the problem outlined:

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.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
template <typename _T>
inline void read(_T &f) {
  f = 0;
  _T fu = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') fu = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    f = (f << 3) + (f << 1) + (c & 15);
    c = getchar();
  }
  f *= fu;
}
template <typename T>
void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x < 10)
    putchar(x + 48);
  else
    print(x / 10), putchar(x % 10 + 48);
}
template <typename T>
void print(T x, char t) {
  print(x);
  putchar(t);
}
template <typename T>
struct hash_map_t {
  vector<T> v, val, nxt;
  vector<int> head;
  int mod, tot, lastv;
  T lastans;
  bool have_ans;
  hash_map_t(int md = 0) {
    head.clear();
    v.clear();
    val.clear();
    nxt.clear();
    tot = 0;
    mod = md;
    nxt.resize(1);
    v.resize(1);
    val.resize(1);
    head.resize(mod);
    have_ans = 0;
  }
  void clear() { *this = hash_map_t(mod); }
  bool count(int x) {
    int u = x % mod;
    for (register int i = head[u]; i; i = nxt[i]) {
      if (v[i] == x) {
        have_ans = 1;
        lastv = x;
        lastans = val[i];
        return 1;
      }
    }
    return 0;
  }
  void ins(int x, int y) {
    int u = x % mod;
    nxt.push_back(head[u]);
    head[u] = ++tot;
    v.push_back(x);
    val.push_back(y);
  }
  int qry(int x) {
    if (have_ans && lastv == x) return lastans;
    count(x);
    return lastans;
  }
};
const int N = 1e5 + 5;
struct ele {
  int u, v, val, id, tag;
  bool operator<(const ele A) const { return val < A.val; }
} a[N * 10];
struct edge_t {
  int u, v, next, val, id;
} G[N << 1];
multiset<int> g[N];
multiset<int>::iterator it;
vector<int> del[N];
int ans[N * 10], f[N], head[N], maxn[N][20], fa[N][20], id[N], d[N], trueid[N],
    vis[N * 10];
int n, m, tot;
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
inline void addedge(int u, int v, int val, int id) {
  G[++tot] = (edge_t){u, v, head[u], val, id}, head[u] = tot;
  G[++tot] = (edge_t){v, u, head[v], val, id}, head[v] = tot;
}
void dfs1(int u, int f) {
  for (register int i = 1; i <= 19; i++) {
    fa[u][i] = fa[fa[u][i - 1]][i - 1];
    maxn[u][i] = max(maxn[u][i - 1], maxn[fa[u][i - 1]][i - 1]);
  }
  for (register int i = head[u]; i; i = G[i].next) {
    int v = G[i].v;
    if (v == f) continue;
    fa[v][0] = u;
    maxn[v][0] = G[i].val;
    id[v] = G[i].id;
    d[v] = d[u] + 1;
    dfs1(v, u);
  }
}
int lca(int u, int v) {
  if (d[u] < d[v]) swap(u, v);
  for (register int i = 19; i >= 0; i--) {
    if (d[fa[u][i]] >= d[v]) {
      u = fa[u][i];
    }
  }
  if (u == v) return u;
  for (register int i = 19; i >= 0; i--) {
    if (fa[u][i] != fa[v][i]) {
      u = fa[u][i];
      v = fa[v][i];
    }
  }
  return fa[u][0];
}
int query(int u, int v) {
  int ans = 0;
  if (d[u] < d[v]) swap(u, v);
  for (register int i = 19; i >= 0; i--) {
    if (d[fa[u][i]] >= d[v]) {
      ans = max(ans, maxn[u][i]);
      u = fa[u][i];
    }
  }
  if (u == v) return ans;
  for (register int i = 19; i >= 0; i--) {
    if (fa[u][i] != fa[v][i]) {
      ans = max(ans, max(maxn[u][i], maxn[v][i]));
      u = fa[u][i];
      v = fa[v][i];
    }
  }
  return max(ans, max(maxn[u][0], maxn[v][0]));
}
void dfs2(int u, int f) {
  trueid[u] = u;
  for (register int i = head[u]; i; i = G[i].next) {
    int v = G[i].v;
    if (v == f) continue;
    dfs2(v, u);
    if (g[trueid[v]].size() < g[trueid[u]].size()) {
      for (it = g[trueid[v]].begin(); it != g[trueid[v]].end(); ++it)
        g[trueid[u]].insert(*it);
      g[trueid[v]].clear();
    } else {
      for (it = g[trueid[u]].begin(); it != g[trueid[u]].end(); ++it)
        g[trueid[v]].insert(*it);
      g[trueid[u]].clear();
      trueid[u] = trueid[v];
    }
  }
  if (u == 1) return;
  for (register unsigned i = 0; i < del[u].size(); i++)
    g[trueid[u]].erase(g[trueid[u]].find(del[u][i]));
  if (g[trueid[u]].size() == 0)
    ans[id[u]] = 1e9;
  else
    ans[id[u]] = *g[trueid[u]].begin();
}
int main() {
  read(n);
  read(m);
  for (register int i = 1; i <= m; i++) {
    read(a[i].u);
    read(a[i].v);
    read(a[i].val);
    a[i].id = i;
  }
  sort(a + 1, a + m + 1);
  for (register int i = 1; i <= n; i++) f[i] = i;
  for (register int i = 1; i <= m; i++) {
    int x = find(a[i].u), y = find(a[i].v);
    if (x != y) {
      f[x] = y;
      a[i].tag = 1;
      vis[a[i].id] = 1;
      addedge(a[i].u, a[i].v, a[i].val, a[i].id);
    }
  }
  d[1] = 1;
  dfs1(1, 0);
  for (register int i = 1; i <= m; i++) {
    if (a[i].tag == 0) {
      ans[a[i].id] = query(a[i].u, a[i].v);
      int d = lca(a[i].u, a[i].v);
      g[a[i].u].insert(a[i].val);
      g[a[i].v].insert(a[i].val);
      del[d].push_back(a[i].val);
      del[d].push_back(a[i].val);
    }
  }
  dfs2(1, 0);
  for (register int i = 1; i <= m; i++)
    if (vis[i] == 0) print(ans[i], '\n');
  return 0;
}

```