Abstract

시간 제한2초메모리 제한2048 MB

요약
값이 DAG를 따라 흐르고 유일한 싱크가 매초 자기 값의 절반을 보존할 때, 모든 값이 0이 되는 최초 시각을 998244353으로 나눈 나머지로 구한다.
난이도

어려움10점 중 8점

유형
위상 정렬, 동적 계획법, 정렬, 시뮬레이션
정답자
아직 제출이 없습니다

문제

You have a DAG (Directed Acyclic Graph) with nn nodes and mm edges. The graph has exactly one node xx that has no outgoing edges. The ii-th node has an integer value a_ia\_i in it.

Every second, the following happens:

  • For each node ii, let b_i=a_ib\_i=a\_i.
  • For each node ii, let a_i=0a\_i=0.
  • For each node ii, and each node jj such that there is an edge from ii to jj, the value b_ib\_i is added to a_ja\_j.
  • The value ⌊b_x2⌋\left\lfloor \frac{b\_x}{2} \right\rfloor is added to a_xa\_x.

Find the first moment of time when all a_ia\_i become 00. Since the answer can be very large, output it modulo 998,244,353998\\,244\\,353.

입력

The first line contains two integers nn and mm (1≤n≤1041\leq n\leq 10^4; 1≤m≤1051 \leq m \leq 10^5): the number of vertices and edges in the graph.

The second line contains nn integers a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n (0≤a_i≤1090 \leq a\_i \leq 10^9): the values in the vertices.

Each of the following mm lines contains two integers uu and vv (1≤u,v≤n1 \leq u, v \leq n) which represent a directed edge from uu to vv.

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 a_ia\_i become 00, modulo 998,244,353998\\,244\\,353.

힌트

Hi, so to me seems like a notorious coincidence. (Codeforces 1704E)

예제3

  1. 예제 1

    입력
    3 2
    1 1 1
    1 2
    2 3
    
    예상 출력
    3
    
  2. 예제 2

    입력
    6 8
    1 1 4 5 1 4
    1 4
    1 5
    2 3
    2 5
    3 4
    4 5
    4 6
    5 6
    
    예상 출력
    8
    
  3. 예제 3

    입력
    5 6
    7 2 3 6 6
    1 2
    1 4
    2 3
    3 4
    3 5
    4 5
    
    예상 출력
    9