Random Interactive MST Bot

시간 제한1초메모리 제한2048 MB

요약
완전 그래프의 간선 가중치를 두 개씩 비교하는 질의만으로 최소 신장 트리를 6000번 이내의 질의로 출력한다.
난이도

보통10점 중 7점

유형
그래프, 최소 신장 트리, 정렬, 구간
정답자
아직 제출이 없습니다

문제

How do setters come up with problems? Sometimes they just take a couple of buzzwords and smash them together. But we are in 2024, so this totally can be outsourced to AI. Introducing our creation based on ChatGPT: RICH B! And its second official problem:

Prompt: Minimum Spanning Tree

Problem: A complete graph with nn nodes and n⋅(n−1)2\frac{n \cdot (n - 1)}{2} edges is chosen. Each edge is randomly assigned a real-valued weight within the range of \[0,1]\[0, 1]. Your task is to find its minimum spanning tree. But you are not given the edges. Instead, you can make queries of the form "? v_1v\_1 u_1u\_1 v_2v\_2 u_2u\_2", and the jury program will respond to you with 11 if the weight of edge (v_1,u_1)(v\_1, u\_1) is less than the weight of edge (v_2,u_2)(v\_2, u\_2), and it will respond with 00 if it's not.

When you think that you know the minimum spanning tree, print it as "! v_1v\_1 u_1u\_1 v_2v\_2 u_2u\_2 …\ldots v_n−1v\_{n - 1} u_n−1u\_{n - 1}", where edges (v_i,u_i)(v\_i, u\_i) form the minimum spanning tree. Constraints: 2≤n≤1002 \le n \le 100, and you can make at most 60006000 queries.

힌트

The Minimum Spanning Tree (MST) of a graph is defined as the graph's spanning tree having the minimum possible total weight.

A spanning tree is a connected subgraph of the given graph that contains all of the graph's vertices and does not contain cycles.

The interactor is not adaptive.

Remember to end the line and flush the output after every line you print. To flush the output, you can use fflush(stdout) in C/C++, System.out.flush() in Java, or sys.stdout.flush() in Python.

예제1

  1. 예제 1

    입력
    3
    
    1
    
    1
    
    예상 출력
    
    ? 1 2 1 3
    
    ? 1 3 2 3
    
    ! 1 2 1 3