結果
| 問題 | No.1451 集団登校 | 
| コンテスト | |
| ユーザー |  titia | 
| 提出日時 | 2025-04-10 00:42:23 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,103 bytes | 
| コンパイル時間 | 385 ms | 
| コンパイル使用メモリ | 12,288 KB | 
| 実行使用メモリ | 16,768 KB | 
| 最終ジャッジ日時 | 2025-04-10 00:42:34 | 
| 合計ジャッジ時間 | 10,472 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 9 WA * 18 | 
ソースコード
import sys
input = sys.stdin.readline
mod=10**9+7
n,m=map(int,input().split())
# UnionFind
Group = [i for i in range(n)] # グループ分け
Nodes = [1]*n # 各グループのノードの数
def find(x):
    while Group[x] != x:
        x=Group[x]
    return x
def Union(x,y):
    if find(x) != find(y):
        if Nodes[find(x)] < Nodes[find(y)]:
            
            #Nodes[find(y)] += Nodes[find(x)]
            #Nodes[find(x)] = 0
            Group[find(x)] = find(y)
            
        else:
            #Nodes[find(x)] += Nodes[find(y)]
            #Nodes[find(y)] = 0
            Group[find(y)] = find(x)
OK=[1]*n
for i in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    k=find(x)
    l=find(y)
    if Nodes[k]<Nodes[l]:
        OK[k]=0
    elif Nodes[k]>Nodes[l]:
        OK[l]=0
    else:
        Union(k,l)
        nx=find(k)
        plus=Nodes[k]+Nodes[l]
        Nodes[k]=0
        Nodes[l]=0
        Nodes[nx]=plus
ANS=[0]*n
for i in range(n):
    if OK[find(i)]==0:
        print(0)
    else:
        x=Nodes[find(i)]
        print(pow(x,mod-2,mod))
            
            
            
        