Logo
(追記) (追記ここまで)

18472번 - Easy Win 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1.5 초 512 MB52151431.111%

문제

V–o_o–V and LHiC are playing a game.

At first, gritukan shows them an undirected graph with n vertices where each edge has a pile of stones on it.

After that, LHiC chooses some non-empty subset of edges of this graph that forms edge-disjoint edgesimple cycles (in other words, each connected component should have an Euler circuit). If he can’t (in other words, if the graph is acyclic), he loses immediately.

Otherwise, LHiC and V–o_o–V play a game of Nim with the piles on the chosen edges. V–o_o–V moves first. In a single move, a player may remove an arbitrary positive number of stones from a single pile. The player who cannot make a move loses.

Let’s call a graph good if LHiC can’t choose a non-empty subset of edge-disjoint cycles on which he will win Nim.

Gritukan asks q queries, can you help him?

There is a set of possible edges which can be picked by gritukan to form a good graph. Initially, this set is empty. In query i, first, an edge i connecting vertices ui and vi, with a pile of ai stones on it and weight wi, is added to the set of possible edges. After that, you should find the largest sum of weights of a good graph that gritukan can form using a subset of edges 1, 2, . . . , i.

입력

The first line contains two integers n and q: the number of vertices in the graph and the number of queries (2 ≤ n ≤ 64, 1 ≤ q ≤ 200 000).

Each of the next q lines contains four integers ui, vi, ai, wi, describing the edge added during i-th query (1 ≤ ui, vi ≤ n, ui ≠ vi , 0 ≤ ai < 260 , 1 ≤ wi ≤ 109).

출력

Print q lines. For the i-th query, you should print the largest sum of weights of a good graph that you can form using a subset of edges 1, 2, . . . , i.

제한

예제 입력 1

3 3
1 2 0 1
2 3 0 1
3 1 0 2

예제 출력 1

1
2
3

예제 입력 2

6 6
1 2 1 1
2 3 1 2
3 4 1 3
4 1 1 4
5 6 1 2
6 5 1 1

예제 출력 2

1
3
6
9
11
11

예제 입력 3

5 5
1 2 0 1
2 3 1 1
3 4 2 3
4 5 4 9
5 1 7 29

예제 출력 3

1
2
5
14
42

예제 입력 4

5 1
3 5 35 35

예제 출력 4

35

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2019 > Day 2: 300iq Contest 2 E번

Contest > Open Cup > 2019/2020 Season > Stage 1: Grand Prix of Kazan E번

  • 문제를 만든 사람: 300iq
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /