結果

問題 No.1190 Points
ユーザー 👑 KazunKazun
提出日時 2021-02-10 02:53:16
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 4,923 bytes
コンパイル時間 1,074 ms
コンパイル使用メモリ 86,756 KB
実行使用メモリ 253,668 KB
最終ジャッジ日時 2023-09-21 18:09:23
合計ジャッジ時間 39,132 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,576 KB
testcase_01 AC 95 ms
71,864 KB
testcase_02 AC 96 ms
72,384 KB
testcase_03 AC 1,236 ms
203,588 KB
testcase_04 AC 1,209 ms
166,596 KB
testcase_05 AC 947 ms
162,956 KB
testcase_06 AC 1,496 ms
217,656 KB
testcase_07 AC 1,605 ms
220,600 KB
testcase_08 AC 1,793 ms
225,604 KB
testcase_09 AC 1,713 ms
210,228 KB
testcase_10 AC 1,601 ms
225,824 KB
testcase_11 AC 1,274 ms
170,064 KB
testcase_12 AC 1,729 ms
223,612 KB
testcase_13 AC 1,404 ms
174,824 KB
testcase_14 AC 580 ms
182,664 KB
testcase_15 AC 1,987 ms
219,128 KB
testcase_16 AC 411 ms
110,268 KB
testcase_17 AC 1,854 ms
212,188 KB
testcase_18 AC 969 ms
122,100 KB
testcase_19 AC 608 ms
215,768 KB
testcase_20 AC 1,257 ms
154,800 KB
testcase_21 AC 657 ms
141,192 KB
testcase_22 AC 810 ms
223,820 KB
testcase_23 TLE -
testcase_24 TLE -
testcase_25 AC 1,676 ms
253,668 KB
testcase_26 AC 1,429 ms
251,472 KB
testcase_27 AC 1,650 ms
252,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Graph:
    #入力定義
    def __init__(self,vertex=[]):
        self.vertex=set(vertex)

        self.edge_number=0
        self.adjacent={v:set() for v in vertex}

    #頂点の追加
    def add_vertex(self,*adder):
        for v in adder:
            if not self.vertex_exist(v):
                self.adjacent[v]=set()
                self.vertex.add(v)

    #辺の追加
    def add_edge(self,u,v):
        self.add_vertex(u)
        self.add_vertex(v)

        if not self.edge_exist(u,v):
            self.adjacent[u].add(v)
            self.adjacent[v].add(u)
            self.edge_number+=1

    #辺を除く
    def remove_edge(self,u,v):
        self.add_vertex(u)
        self.add_vertex(v)

        if self.edge_exist(u,v):
            self.adjacent[u].discard(v)
            self.adjacent[v].discard(u)
            self.edge_number-=1

    #頂点を除く
    def remove_vertex(self,*vertexes):
        for v in vertexes:
            if self.vertex_exist(v):
                U=self.neighbohood(v)
                for u in U:
                    self.edge_number-=1
                    self.adjacent[u].discard(v)

                del self.adjacent[v]
                self.vertex.discard(v)

    #Walkの追加
    def add_walk(self,*walk):
        n=len(walk)
        for i in range(n-1):
            self.add_edge(walk[i],walk[i+1])

    #Cycleの追加
    def add_cycle(self,*cycle):
        self.add_walk(*cycle)
        self.add_edge(cycle[-1],cycle[0])

    #頂点の交換
    def __vertex_swap(self,p,q):
        self.vertex.sort()

    #グラフに頂点が存在するか否か
    def vertex_exist(self,v):
        return v in self.vertex

    #グラフに辺が存在するか否か
    def edge_exist(self,u,v):
        if not(self.vertex_exist(u) and self.vertex_exist(v)):
            return False
        return v in self.adjacent[u]

    #近傍
    def neighbohood(self,v):
        if not self.vertex_exist(v):
            return []
        return list(self.adjacent[v])

    #次数
    def degree(self,v):
        if not self.vertex_exist(v):
            return 0

        return len(self.adjacent[v])

    #頂点数
    def vertex_count(self):
        return len(self.vertex)

    #辺数
    def edge_count(self):
        return self.edge_number

    #頂点vを含む連結成分
    def connected_component(self,v):
        if v not in self.adjacent:
            return []

        from collections import deque
        T={u:0 for u in self.vertex}
        T[v]=1
        Q=deque([v])
        while Q:
            u=Q.popleft()
            for w in self.adjacent[u]:
                if not T[w]:
                    T[w]=1
                    Q.append(w)
        return [x for x in self.adjacent if T[x]]

    #距離
    def distance(self,u,v):
        from collections import deque
        inf=float("inf")
        T={v:inf  for v in self.vertex}

        if u==v:
            return 0
        Q=deque([u])
        T[u]=0
        while Q:
            w=Q.popleft()
            for x in self.adjacent[w]:
                if T[x]==inf:
                    T[x]=T[w]+1
                    Q.append(x)
                    if x==v:
                        return T[x]
        return inf

    #ある1点からの距離
    def distance_all(self,u):
        from collections import deque
        inf=float("inf")
        T={v:inf  for v in self.vertex}

        Q=deque([u])
        T[u]=0
        while Q:
            w=Q.popleft()
            for x in self.adjacent[w]:
                if T[x]==inf:
                    T[x]=T[w]+1
                    Q.append(x)
        return T

    #最短路
    def shortest_path(self,u,v):
        from collections import deque
        inf=float("inf")
        T={v:None for v in self.vertex}

        if u==v:
            return [u]

        Q=deque([u])
        T[u]=u
        while Q:
            w=Q.popleft()
            for x in self.adjacent[w]:
                if not T[x]:
                    T[x]=w
                    Q.append(x)
                    if x==v:
                        P=[v]
                        a=v
                        while a!=u:
                            a=T[a]
                            P.append(a)
                        return P[::-1]
        return None

    #何かしらの頂点を選ぶ.
    def poping_vertex(self):
        v=self.vertex.pop()
        self.vertex.add(v)
        return v
#================================================
N,M,P=map(int,input().split())
X=Graph([(i,j) for i in range(1,N+1) for j in [0,1]])

S,G=map(int,input().split())
for _ in range(M):
    u,v=map(int,input().split())
    X.add_edge((u,0),(v,1))
    X.add_edge((u,1),(v,0))

p=P%2
A=X.distance_all((S,p))
B=X.distance_all((G,0))

K=[]
for i in range(1,N+1):
    if min(A[(i,0)]+B[(i,0)],A[(i,1)]+B[(i,1)])<=P:
        K.append(i)

if K:
    print(len(K),*K,sep="\n")
else:
    print(-1)
assert 1
0