Orig Description
E: Mischief Graph
Problem
You were solving the flow problem, which is typical as a graph algorithm.
In the problem given, the graph has $N$ vertices and $M$ edges, and an edge with capacity $z_i$ and cost $d_i$ is connected from vertex $x_i$ to vertex $y_i$.
However, AOR Squid mischievously shuffled the order of $x_i, y_i,$ and $z_i$, and the vertex and capacity information became indistinguishable.
Therefore, you gave up finding the flow between $s-t$ and decided to find the shortest distance between $s-t$.
You decided to create an edge with cost $d_i$ from two input cases $a_i, b_i, c_i$ whose order of $x_i, y_i,$ and $z_i$ was shuffled and turned into two vertex information. That is, one of the three candidates, $a_i$ to $b_i$, $a_i$ to $c_i$, and $b_i$ to $c_i$, has an edge with cost $d_i$.
Find the minimum value of "the shortest distance from s to t" among the possible graphs.
Constraints
$2 \le N \le 10^5$
$1 \le M \le 10^5$
$1 \le s,t \le N$
$1 \le a_i,b_i,c_i \le N$
$1 \le d_i \le 10^9$
$s \neq t$
A path from $s$ to $t$ exists in the original graph
The input consists of integers only
Input
$N \ M \ s \ t$
$a_1 \ b_1 \ c_1 \ d_1$
$\vdots$
$a_M \ b_M \ c_M \ d_M$
Output
Output the minimum value of "the shortest distance from $s$ to $t$" among the possible graphs in one line. You must also output a newline at the end.
Sample
Sample Input 1
5 3 1 4
3 1 2 5
3 4 2 3
5 4 2 2
Sample Output 1
7
Sample Input 2
8 5 8 3
4 5 1 2
5 6 2 3
7 8 5 12
3 1 2 11
1 2 3 10
Sample Output 2
24
Extracted Specification
An integer N (2 ≤ N ≤ 10^5), representing some quantity or size.
An integer M (1 ≤ M ≤ 10^5), representing some quantity or size.
An integer s (1 ≤ s ≤ N), representing some quantity or size.
An integer t (1 ≤ t ≤ N), representing some quantity or size.
M tuples of four integers (a_i, b_i, c_i, d_i) where 1 ≤ a_i, b_i, c_i ≤ N and 1 ≤ d_i ≤ 10^9.
### Example Input:
```
5 3 1 4
3 1 2 5
3 4 2 3
5 4 2 2
```
### Function Signature:
Write a function f(N, M, s, t, edges) that takes in the input.
```python
def f(N: int, M: int, s: int, t: int, edges: List[Tuple[int, int, int, int]]):
'''
N: an integer
M: an integer
s: an integer
t: an integer
edges: a list of tuples, each containing four integers
'''
```
Test Case Generator
To create a test case generator for the given competitive programming problem "E: Mischief Graph," we need to generate test cases that adhere to the constraints and input format specified in the problem statement. Here's how the test case generator can be implemented in Python:
```python
import random
def tcgen():
# Constraints
N = random.randint(2, 10**5)
M = random.randint(1, 10**5)
s = random.randint(1, N)
t = random.randint(1, N)
# Ensure s != t
while s == t:
t = random.randint(1, N)
edges = []
for _ in range(M):
a_i = random.randint(1, N)
b_i = random.randint(1, N)
c_i = random.randint(1, N)
# Ensure all three values are different
while len(set([a_i, b_i, c_i])) != 3:
a_i = random.randint(1, N)
b_i = random.randint(1, N)
c_i = random.randint(1, N)
d_i = random.randint(1, 10**9)
edges.append((a_i, b_i, c_i, d_i))
return N, M, s, t, edges
def format_test_case(N, M, s, t, edges):
test_case = f"{N} {M} {s} {t}\n"
for a_i, b_i, c_i, d_i in edges:
test_case += f"{a_i} {b_i} {c_i} {d_i}\n"
return test_case
if __name__ == "__main__":
N, M, s, t, edges = tcgen()
test_case = format_test_case(N, M, s, t, edges)
print(test_case)
```
### Explanation:
1. **Constraints Handling**:
- `N`, `M`: Randomly generate the number of vertices and edges within the given constraints.
- `s`, `t`: Randomly generate the source and target vertices ensuring `s` is different from `t`.
2. **Edges Generation**:
- Each edge is represented by three vertices and a cost. We ensure that the three vertices (`a_i`, `b_i`, `c_i`) are distinct by checking the length of the set created from these vertices.
- The cost `d_i` is randomly generated within the given range.
3. **Formatting the Test Case**:
- We create a string representation of the test case in the required format.
4. **Execution**:
- Running the script will print out a randomly generated test case.
This test case generator ensures that the generated test cases are valid and adhere to the constraints provided in the problem statement.
Extract Arguments
def extract_arguments(fh):
N, M, s, t = map(int, fh.readline().strip().split())
edges = []
for _ in range(M):
a, b, c, d = map(int, fh.readline().strip().split())
edges.append((a, b, c, d))
return N, M, s, t, edges