Problem p01978 - Generation 2

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 lines of four integers each: a_i, b_i, c_i, d_i (1 ≤ a_i, b_i, c_i ≤ N and 1 ≤ d_i ≤ 10^9), representing some quantities or sizes.

### 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 of four integers
    '''
```

Test Case Generator

Sure! Here is a test case generator for the "Mischief Graph" problem:

```python
import random

def generate_test_case():
    # Define N and M within the given constraints
    N = random.randint(2, 10**5)
    M = random.randint(1, 10**5)
    
    # Define s and t ensuring s != t
    s = random.randint(1, N)
    t = random.randint(1, N)
    while t == s:
        t = random.randint(1, N)
    
    # Generate edges with a_i, b_i, c_i, d_i
    edges = []
    for _ in range(M):
        a_i = random.randint(1, N)
        b_i = random.randint(1, N)
        c_i = random.randint(1, N)
        while b_i == a_i:
            b_i = random.randint(1, N)
        while c_i == a_i or c_i == b_i:
            c_i = random.randint(1, N)
        d_i = random.randint(1, 10**9)
        edges.append((a_i, b_i, c_i, d_i))
    
    # Format the output
    input_str = f"{N} {M} {s} {t}\n"
    for a_i, b_i, c_i, d_i in edges:
        input_str += f"{a_i} {b_i} {c_i} {d_i}\n"
    
    return input_str

# Example of generating a test case
print(generate_test_case())
```

This script generates random test cases for the "Mischief Graph" problem. It ensures that the constraints are met and that `s` and `t` are different vertices. Each edge is represented by three vertex identifiers and a cost, with the vertices shuffled randomly. 

Note: Running this script for large values of `N` and `M` can produce very large output, as specified in the constraints. Make sure your environment can handle these sizes before executing it.

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