This repository has been archived on 2026-05-22. You can view files and clone it, but cannot push or open issues or pull requests.
Files
ICPC-2017/asecbadge_iter.py

51 lines
861 B
Python

from collections import deque, defaultdict
N, L, B = map(int, input().split())
S, D = map(int, input().split())
rooms = defaultdict(dict)
bounds = set()
for _ in range(L):
a, b, x, y = map(int, input().split())
rooms[a][b] = x, y + 1
bounds.add(x)
bounds.add(y + 1)
total = 0
bounds = sorted(bounds)
def piecewise(seq):
it = iter(seq)
last = next(it)
for new in it:
yield last, new
last = new
for a, b in piecewise(bounds):
q = deque([S])
visited = [0] * L
while q:
curr = q.pop()
visited[curr - 1] = 1
nbors = rooms[curr].items()
if curr == D:
total += b - a
break
for n, (la, lb) in nbors:
if visited[n - 1]:
continue
if a >= la and b <= lb:
q.append(n)
print(total)