結果

問題 No.3341 Making Beautiful Graphs
コンテスト
ユーザー detteiuu
提出日時 2026-01-29 17:01:16
言語 PyPy3
(7.3.17)
結果
WA  
実行時間 -
コード長 1,063 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 341 ms
コンパイル使用メモリ 82,396 KB
実行使用メモリ 79,988 KB
最終ジャッジ日時 2026-01-29 17:01:24
合計ジャッジ時間 7,741 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 WA * 47
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import deque
from random import randrange

N = int(input())

if N == 1 or N == 2:
    exit(print(-1))

def MOD1(a):
    while N2 < a:
        a -= N2
    return a

N2 = N**2
while True:
    a, b, c, d = randrange(1, N2), randrange(1, N2), randrange(1, N2), randrange(1, N2)
    if len(set([a, b, c, d])) < 4:
        continue
    if (a+b+c+d)%N2 != 0:
        continue
    edge = []
    for i in range(1, N2+1):
        E = [i+a, i+b, i+c, i+d]
        for j in range(4):
            E[j] = MOD1(E[j])
        for e in E:
            edge.append((i, e))

    G = [[] for _ in range(N2)]
    for u, v in edge:
        u, v = u-1, v-1
        G[u].append(v)
    visited = [-1]*N2
    visited[0] = 0
    que = deque()
    que.append(0)
    while que:
        n = que.popleft()
        for v in G[n]:
            if visited[v] == -1:
                visited[v] = visited[n]+1
                que.append(v)

    if max(visited) <= N:
        print(len(edge)//2)
        for u, v in edge:
            if u < v:
                print(u, v)
        break
0