結果

問題 No.3087 University Coloring
ユーザー Facade
提出日時 2025-04-04 22:58:59
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 977 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 82,580 KB
実行使用メモリ 316,928 KB
最終ジャッジ日時 2025-04-04 22:59:11
合計ジャッジ時間 9,641 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 3 WA * 12 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**8)
n,m=map(int,input().split())
connect=[[] for _ in range(n)]
weight=[]
ans=0
for i in range(m):
    a,b,c=map(int,input().split())
    a-=1
    b-=1
    connect[a].append((b,i))
    connect[b].append((a,i))
    weight.append(c)
    ans+=c
def DFS(now,past,edge):
    global visited
    global ans
    for to,ed in connect[now]:
        if visited[to] and to!=past and len(edge)>=2:
            idx=0
            check=ed
            for i in range(len(edge)):
                if check==ed:
                    idx=i
                    break
            ret=10**18
            for i in range(idx,len(edge)):
                ret=min(ret,weight[edge[i]])
            ans-=ret
            return 
        else:
            if not visited[to]:
                visited[to]=True
                edge.append(ed)
                DFS(to,now,edge)
                edge.pop()
            

visited=[False]*n
visited[0]=True
DFS(0,-1,[])
print(ans*2)
0