結果
問題 | No.1612 I hate Construct a Palindrome |
ユーザー |
![]() |
提出日時 | 2024-06-13 23:25:44 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,554 bytes |
コンパイル時間 | 474 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 65,664 KB |
最終ジャッジ日時 | 2024-06-13 23:25:58 |
合計ジャッジ時間 | 12,456 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | AC * 13 TLE * 1 -- * 22 |
ソースコード
import syssys.setrecursionlimit(1000006)# sys.set_int_max_str_digits(200005)int1 = lambda x: int(x)-1pDB = lambda *x: print(*x, end="\n", file=sys.stderr)p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)def II(): return int(sys.stdin.readline())def LI(): return list(map(int, sys.stdin.readline().split()))def LLI(rows_number): return [LI() for _ in range(rows_number)]def LI1(): return list(map(int1, sys.stdin.readline().split()))def LLI1(rows_number): return [LI1() for _ in range(rows_number)]def SI(): return sys.stdin.readline().rstrip()dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]# inf = -1-(-1 << 31)inf = -1-(-1 << 62)# md = 10**9+7md = 998244353def dfs(ok,u):if ok(u):return ufor v,i in to[u]:if fin[v]:continuefin[v]=1ii.append(i)ret=dfs(ok,v)if ret!=-1:return retii.pop()fin[v]=0return -1n,m=LI()to=[[] for _ in range(n)]cc=[]for i in range(m):u,v,c=SI().split()u=int1(u)v=int1(v)c=ord(c)-97to[u].append((v,i))to[v].append((u,i))cc.append(c)if all(c==cc[0] for c in cc):print(-1)exit()s,si=to[0][0]ii=[si]fin=[0]*nfin[s]=1ok1=lambda x:cc[ii[-1]]!=cc[si]v=dfs(ok1,s)# print(ii,v)if v!=n-1:pre,ii=ii,[]fin=[0]*nfin[v]=1ok2=lambda x:x==n-1dfs(ok2,v)ii=pre+ii# print(ii)ee=[cc[i] for i in ii]if ee==ee[::-1]:ii=[si,si]+iiprint(len(ii))for i in ii:print(i+1)