結果

問題 No.1399 すごろくで世界旅行 (構築)
ユーザー lam6er
提出日時 2025-04-15 21:22:28
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 714 bytes
コンパイル時間 338 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 83,608 KB
最終ジャッジ日時 2025-04-15 21:28:45
合計ジャッジ時間 23,739 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

V, D = map(int, input().split())

# Initialize adjacency matrix with 0s (1-based indexing)
E = [[0] * (V + 1) for _ in range(V + 1)]

# Connect each node to its previous and next nodes in a circular manner
for i in range(1, V + 1):
    prev = i - 1 if i > 1 else V
    next_node = i + 1 if i < V else 1
    E[i][prev] = 1
    E[i][next_node] = 1
    E[prev][i] = 1  # Since the graph is undirected
    E[next_node][i] = 1

# For even V, add an additional edge to create an odd cycle
if V % 2 == 0:
    mid = (V // 2) + 1
    E[1][mid] = 1
    E[mid][1] = 1

# Output the matrix (1-based to 0-based conversion for rows and columns)
for i in range(1, V + 1):
    print(''.join(str(E[i][j]) for j in range(1, V + 1)))
0