結果
問題 | No.1436 Rgaph |
ユーザー | tyawanmusi |
提出日時 | 2020-11-01 12:52:38 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,069 bytes |
コンパイル時間 | 375 ms |
コンパイル使用メモリ | 82,392 KB |
実行使用メモリ | 85,376 KB |
最終ジャッジ日時 | 2024-07-22 14:32:07 |
合計ジャッジ時間 | 5,003 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
52,948 KB |
testcase_01 | AC | 33 ms
52,956 KB |
testcase_02 | WA | - |
testcase_03 | AC | 36 ms
52,732 KB |
testcase_04 | WA | - |
testcase_05 | AC | 35 ms
53,104 KB |
testcase_06 | WA | - |
testcase_07 | AC | 35 ms
54,452 KB |
testcase_08 | WA | - |
testcase_09 | AC | 36 ms
52,752 KB |
testcase_10 | WA | - |
testcase_11 | AC | 45 ms
63,556 KB |
testcase_12 | AC | 46 ms
63,612 KB |
testcase_13 | AC | 45 ms
63,696 KB |
testcase_14 | AC | 53 ms
71,480 KB |
testcase_15 | AC | 45 ms
58,168 KB |
testcase_16 | AC | 54 ms
71,616 KB |
testcase_17 | AC | 71 ms
84,324 KB |
testcase_18 | AC | 57 ms
74,608 KB |
testcase_19 | AC | 56 ms
74,620 KB |
testcase_20 | AC | 63 ms
78,820 KB |
testcase_21 | AC | 60 ms
78,400 KB |
testcase_22 | AC | 84 ms
81,760 KB |
testcase_23 | AC | 81 ms
84,132 KB |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | AC | 101 ms
85,184 KB |
testcase_28 | RE | - |
testcase_29 | AC | 119 ms
84,628 KB |
ソースコード
import sys input = lambda:sys.stdin.readline().rstrip() def scc(n, edge): redge=[[]for _ in range(n)] for i in range(n): for j in edge[i]: redge[j].append(i) order=[] used=[0]*n group=[-1]*n def dfs(u): used[u]=1 for v in edge[u]: if not used[u]: dfs(v) order.append(u) def rdfs(u,c): group[u]=c used[u]=1 for v in redge[u]: if not used[v]: rdfs(v,c) for i in range(n): if not used[i]: dfs(i) used=[0]*n x=0 for u in order: if not used[u]: rdfs(u,x) x+=1 return x,group def bipartite_graph_check(n, edge): color = [-1] * n for i in range(n): if color[i] != -1: continue stack = [i] color[i] = 0 for node in stack: for mode in edge[node]: if color[mode] == -1: stack.append(mode) color[mode] = color[node] ^ 1 elif color[mode] == color[node]: return False return True n,m=map(int,input().split()) edge=[[] for _ in range(n)] edges=[[-1]*n for _ in range(n)] for i in range(m): a,b=map(int,input().split()) a-=1 b-=1 edge[a].append(b) edges[a][b]=i if bipartite_graph_check(n,edge): exit(print(-1)) label,_=scc(n,edge) if label!=1: exit(print(-1)) x=[] for i in range(n): used=[0]*n co=[0]*n stack=[i] flag=False for u in stack: for v in edge[u]: if used[v]:continue used[v]=1 co[v]=co[u]+1 if i==v: flag=True break stack.append(v) if flag: break x.append(co[i]) s=x.index(min(x)) stack=[s] root=[-1]*n for u in stack: for v in edge[u]: if s==v: x=[u] while root[u]!=-1: u=root[u] x.append(u) ans=["R"]*m x=x[::-1] if len(x)==n: x.append(x[0]) for i in range(n): if i%2==0: ans[edges[x[i]][x[i+1]]]="G" else: for i in range(len(x)//2+1): ans[edges[x[i]][x[i+1]]]="G" print("".join(ans)) exit() if root[v]!=-1: continue root[v]=u stack.append(v)