結果

問題 No.1170 Never Want to Walk
ユーザー Craft Boss
提出日時 2025-10-07 20:40:27
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,274 bytes
コンパイル時間 419 ms
コンパイル使用メモリ 82,104 KB
実行使用メモリ 282,864 KB
最終ジャッジ日時 2025-10-07 20:40:35
合計ジャッジ時間 6,974 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25 TLE * 1 -- * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

class stationConectivity():
    def __init__(self, num_station):
        self.parent = [-1]*(num_station)

    def find(self, id):
        if self.parent[id]<0:
            return id
        else:
            self.parent[id] = self.find(self.parent[id])
            return self.parent[id]

    def union(self, xi, A, B):
        for i, x in enumerate(xi):
            for j, upTox in enumerate(xi[:i]):
                if x-upTox < A:
                    break
                if x-upTox <= B:
                    x_root = self.find(i)
                    upTox_root = self.find(j)
                    if x_root != upTox_root:
                        if self.parent[x_root] > self.parent[upTox_root]:
                            x_root, upTox_root = upTox_root, x_root
                        self.parent[x_root] += self.parent[upTox_root]
                        self.parent[upTox_root] = x_root
    
    def countReachable(self, id):
        return self.parent[self.find(id)]*-1

def main():
    num_station, A, B = map(int, input().split())
    xi = list(map(int, input().split()))

    railway = stationConectivity(num_station)

    railway.union(xi, A, B)

    for i in range(num_station):
        print(railway.countReachable(i))

if __name__ == "__main__":
    main()
0