QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#10371. Xiao Xiu and Xiao Dong's Spanning Tree

Statistics

This is not a submission-based problem.

This is not an interactive problem.

Xiao Xiu and Xiao Dong are building a spanning forest together.

They each have a graph with $n$ vertices and $m$ edges. They want to select a subset of edges such that the graph containing only these edges is a forest or a unicyclic forest.

Since Xiao Xiu and Xiao Dong are a couple, they decide to make the same choices. Specifically, for the $i$-th edge, both of them must either select it or not select it.

Each $i$-th edge has a weight $a_i$. Xiao Xiu and Xiao Dong want to maximize the total weight of the selected edges.

Here, a unicyclic forest is defined as a graph where each connected component is either a tree or a unicyclic graph (a graph with exactly one cycle).

Input

The first line contains two integers $n$ and $m$, representing the number of vertices and edges in the graphs.

The next line contains two integers $\text{type}_1$ and $\text{type}_2$, representing the requirements for the final graph for Xiao Xiu and Xiao Dong, respectively. If $\text{type}$ is $1$, the requirement is a forest; if $\text{type}$ is $2$, the requirement is a unicyclic forest.

The next $m$ lines each contain five integers $u1_i, v1_i, u2_i, v2_i, a_i$, where $u1_i, v1_i$ are the vertices connected by the edge in Xiao Xiu's graph, and $u2_i, v2_i$ are the vertices connected by the edge in Xiao Dong's graph.

The input does not guarantee the absence of multiple edges or self-loops.

Output

Output a single integer representing the maximum total edge weight.

Examples

Input 1

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

Output 1

4

Subtasks

For all data, $1 \le n, m \le 300$ and $1 \le a_i \le 10^5$.

Unless otherwise specified, the following limits apply.

Subtask ID $n$ $m$ Special Constraints Score
1 $300$ $300$ $u1_i=u2_i, v1_i=v2_i$ 3
2 $20$ None 3
3 $7$ $300$ $\text{type}_1=\text{type}_2=1$ 7
4 $5$ None 11
5 $300$ $\text{type}_1=\text{type}_2=1$ 15
6 17
7 $70$ $70$ None 10
8 $300$ $300$ 34

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.