Abstract
시간 제한2초메모리 제한2048 MB
값이 DAG를 따라 흐르고 유일한 싱크가 매초 자기 값의 절반을 보존할 때, 모든 값이 0이 되는 최초 시각을 998244353으로 나눈 나머지로 구한다.
문제
You have a DAG (Directed Acyclic Graph) with nodes and edges. The graph has exactly one node that has no outgoing edges. The -th node has an integer value in it.
Every second, the following happens:
- For each node , let .
- For each node , let .
- For each node , and each node such that there is an edge from to , the value is added to .
- The value is added to .
Find the first moment of time when all become . Since the answer can be very large, output it modulo .
입력
The first line contains two integers and (; ): the number of vertices and edges in the graph.
The second line contains integers (): the values in the vertices.
Each of the following lines contains two integers and () which represent a directed edge from to .
It is guaranteed that the graph is a DAG with no multi-edges, and there is exactly one node that has no outgoing edges.
출력
Print a line with a single integer: the first moment of time when all become , modulo .
힌트
Hi, so to me seems like a notorious coincidence. (Codeforces 1704E)