結果
| 問題 |
No.1436 Rgaph
|
| コンテスト | |
| ユーザー |
qwewe
|
| 提出日時 | 2025-04-24 12:32:52 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,436 bytes |
| コンパイル時間 | 685 ms |
| コンパイル使用メモリ | 82,172 KB |
| 実行使用メモリ | 64,820 KB |
| 最終ジャッジ日時 | 2025-04-24 12:34:15 |
| 合計ジャッジ時間 | 5,592 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 19 WA * 9 |
ソースコード
import sys
from collections import deque
def main():
input = sys.stdin.read().split()
idx = 0
N = int(input[idx])
idx += 1
M = int(input[idx])
idx += 1
edges = []
adj = [[] for _ in range(N+1)] # 1-based
for _ in range(M):
a = int(input[idx])
idx += 1
b = int(input[idx])
idx += 1
edges.append((a, b))
adj[a].append(b)
adj[b].append(a) # for undirected bipartition check
# Check if the underlying undirected graph is bipartite
color = [-1] * (N + 1)
is_bipartite = True
for u in range(1, N+1):
if color[u] == -1:
queue = deque()
queue.append(u)
color[u] = 0
while queue:
v = queue.popleft()
for nei in adj[v]:
if color[nei] == -1:
color[nei] = color[v] ^ 1
queue.append(nei)
elif color[nei] == color[v]:
is_bipartite = False
break
if not is_bipartite:
break
if not is_bipartite:
break
if is_bipartite:
print(-1)
return
# If not bipartite, output alternating R and G
res = []
for i in range(M):
res.append('R' if i % 2 == 0 else 'G')
print(''.join(res))
if __name__ == '__main__':
main()
qwewe