Codeforces Round 334 (Div. 1)
E
Pastoral Oddities
Codeforces
3000
原题
← D→
翻译中…

In the land of Bovinia there are $*n*$ pastures, but no paths connecting the pastures. Of course, this is a terrible situation, so Kevin Sun is planning to rectify it by constructing $*m*$ undirected paths connecting pairs of distinct pastures. To make transportation more efficient, he also plans to pave some of these new paths.

翻译中…

Kevin is very particular about certain aspects of path-paving. Since he loves odd numbers, he wants each pasture to have an odd number of paved paths connected to it. Thus we call a paving sunny if each pasture is incident to an odd number of paved paths. He also enjoys short paths more than long paths, so he would like the longest paved path to be as short as possible. After adding each path, Kevin wants to know if a sunny paving exists for the paths of Bovinia, and if at least one does, the minimum possible length of the longest path in such a paving. Note that "longest path" here means maximum-weight edge.

翻译中…

Input

翻译中…

The first line contains two integers $*n*$ ($2 ≤ *n* ≤ 100 000$) and $*m*$ ($1 ≤ *m* ≤ 300 000$), denoting the number of pastures and paths, respectively. The next $*m*$ lines each contain three integers $*a*_{*i*}$, $*b*_{*i*}$ and $*l*_{*i*}$, describing the $*i*$-th path. The $*i*$-th path connects pastures $*a*_{*i*}$ and $*b*_{*i*}$ ($1 ≤ *a*_{*i*}, *b*_{*i*} ≤ *n*$; $*a*_{*i*} ≠ *b*_{*i*}$) and has length $*l*_{*i*}$ ($1 ≤ *l*_{*i*} ≤ 10^{9}$). Paths are given in the order in which they are constructed.

翻译中…

Output

翻译中…

Output $*m*$ lines. The $*i*$-th line should contain a single integer denoting the minimum possible length of the longest path (maximum-weight edge) in a sunny paving using only the first $*i*$ paths. If Kevin cannot pave a set of paths so that each pasture is incident to an odd number of paved paths, output $- 1$.

翻译中…

Note that the paving is only hypothetical—your answer after adding the $*i*$-th path should not be affected by any of your previous answers.

翻译中…

Note

翻译中…

For the first sample, these are the paths that Kevin should pave after building the $*i*$-th path:

翻译中…
  1. No set of paths works.
  2. Paths 1 (length $4$) and 2 (length $8$).
  3. Paths 1 (length $4$) and 2 (length $8$).
  4. Paths 3 (length $2$) and 4 (length $3$).
翻译中…

In the second sample, there never exists a paving that makes Kevin happy.

翻译中…

样例

Input #1
4 4
1 3 4
2 4 8
1 2 2
3 4 3
Output #1
-1
8
8
3
InputCopy OutputCopy
Input #2
3 2
1 2 3
2 3 4
Output #2
-1
-1
InputCopy OutputCopy
Input #3
4 10
2 1 987
3 2 829
4 1 768
4 2 608
3 4 593
3 2 488
4 2 334
2 1 204
1 3 114
1 4 39
Output #3
-1
-1
829
829
768
768
768
488
334
204
InputCopy OutputCopy
题目信息
题号
603E
时间限制
4 s
内存限制
256 MB
标签
数据结构
分治
并查集
数学
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。