CF1137C.Museums Tour

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In the country NN, there are nn cities connected by mm one-way roads. Although this country seems unremarkable, there are two interesting facts about it. At first, a week lasts dd days here. At second, there is exactly one museum in each city of the country NN.

Travel agency "Open museums" is developing a new program for tourists interested in museums. Agency's employees know which days each of the museums is open. The tour should start in the capital — the city number 11, and the first day of the tour must be on the first day of a week. Each day a tourist will be in some city, watching the exposition in its museum (in case museum is open today), and by the end of the day, the tour either ends or the tourist goes into another city connected by a road with the current one. The road system of NN is designed in such a way that traveling by a road always takes one night and also all the roads are one-way. It's allowed to visit a city multiple times during the trip.

You should develop such route for the trip that the number of distinct museums, possible to visit during it, is maximum.

在国家 NN 中,有 nn 座城市,由 mm 条单向道路连接。尽管这个国家看似平凡,但它却有两个有趣的事实:第一,这里的一周持续 dd 天;第二,国家 NN 的每座城市中恰好有一座博物馆。

旅行社“开放博物馆”正在为对博物馆感兴趣的游客开发一项新旅游项目。该旅行社的员工已知每座博物馆在一周中的哪些天开放。旅行必须从首都——即编号为 11 的城市——出发,且旅行的第一天必须是一周的第一天。每天,游客将身处某座城市,并参观该市博物馆的展览(前提是该博物馆当天开放);到当天结束时,旅行要么终止,要么游客经由一条与当前城市相连的道路前往另一座城市。国家 NN 的道路系统设计使得沿任意道路通行总需耗费一个夜晚,且所有道路均为单向。在旅行过程中,允许重复访问同一座城市。

你需要规划一条旅行路线,使得在该路线中能够参观到的不同博物馆的数量最大化。

输入格式

The first line contains three integers nn, mm and dd (1≤n≤100 0001 \leq n \leq 100\,000, 0≤m≤100 0000 \leq m \leq 100\,000, 1≤d≤501 \leq d \leq 50), the number of cities, the number of roads and the number of days in a week.

Each of next mm lines contains two integers uiu_i and viv_i (1≤ui,vi≤n1 \le u_i, v_i \le n, ui≠viu_i \ne v_i), denoting a one-way road from the city uiu_i to the city viv_i.

The next nn lines contain the museums' schedule. The schedule of the museum located in the ii-th city is described in the ii-th of these lines. Each line consists of exactly dd characters "0" or "1", the jj-th character of the string equals to "1" if the museum is open at the jj-th day of a week, and "0", otherwise.

It's guaranteed that for each pair of cities (u,v)(u, v) there exists no more than one road leading from uu to vv.

第一行包含三个整数 nn、mm 和 dd(1≤n≤100 0001 \leq n \leq 100\,000,0≤m≤100 0000 \leq m \leq 100\,000,1≤d≤501 \leq d \leq 50),分别表示城市的数量、道路的数量以及一周的天数。

接下来的 mm 行,每行包含两个整数 uiu_i 和 viv_i(1≤ui,vi≤n1 \le u_i, v_i \le n,ui≠viu_i \ne v_i),表示一条从城市 uiu_i 到城市 viv_i 的单向道路。

接下来的 nn 行描述各博物馆的开放时间表。其中第 ii 行描述位于第 ii 个城市的博物馆的时间表。每行恰好包含 dd 个字符,每个字符为 "0" 或 "1";该字符串的第 jj 个字符为 "1" 表示该博物馆在每周的第 jj 天开放,为 "0" 表示不开放。

保证对于任意一对城市 (u,v)(u, v),至多只存在一条从 uu 到 vv 的道路。

输出格式

Print a single integer — the maximum number of distinct museums, that it's possible to visit, starting a trip in the first city on the first day of the week.

输出一个整数——从第一座城市、一周的第一天开始旅行,最多可以参观的不同博物馆的数量。

输入输出样例

  • 输入#1

    4 5 3
    3 1
    1 2
    2 4
    4 1
    2 3
    011
    110
    111
    001

    输出#1

    3
  • 输入#2

    3 3 7
    1 2
    1 3
    2 3
    1111111
    0000000
    0111111

    输出#2

    2

说明/提示

Explanation of the first example

The maximum number of distinct museums to visit is 33. It's possible to visit 33 museums, for example, in the way described below.

  • Day 1. Now it's the 1st day of a week, and the tourist is in the city 11. The museum there is closed. At night the tourist goes to the city number 22.
  • Day 2. Now it's the 2nd day of a week, and the tourist is in the city 22. The museum there is open, and the tourist visits it. At night the tourist goes to the city number 44.
  • Day 3. Now it's the 3rd day of a week, and the tourist is in the city 44. The museum there is open, and the tourist visits it. At night the tourist goes to the city number 11.
  • Day 4. Now it's the 1st day of a week, and the tourist is in the city 11. The museum there is closed. At night the tourist goes to the city number 22.
  • Day 5. Now it's the 2nd of a week number 22, and the tourist is in the city 22. The museum there is open, but the tourist has already visited it. At night the tourist goes to the city number 33.
  • Day 6. Now it's the 3rd day of a week, and the tourist is in the city 33. The museum there is open, and the tourist visits it. After this, the tour is over.

Explanation of the second example

The maximum number of distinct museums to visit is 22. It's possible to visit 22 museums, for example, in the way described below.

  • Day 1. Now it's the 1st day of a week, and the tourist is in the city 11. The museum there is open, and the tourist visits it. At night the tourist goes to the city number 22.
  • Day 2. Now it's the 2nd day of a week, and the tourist is in the city 22. The museum there is closed. At night the tourist goes to the city number 33.
  • Day 3. Now it's the 3rd day of a week, and the tourist is in the city 33. The museum there is open, and the tourist visits it. After this, the tour is over.

第一个样例的说明!

最多可参观的不同博物馆数量为 33。例如,可通过如下方式参观 33 个博物馆:

  • 第 1 天:当前是一周中的第 1 天,游客位于城市 11。该城市的博物馆关闭。夜间,游客前往城市 22。
  • 第 2 天:当前是一周中的第 2 天,游客位于城市 22。该城市的博物馆开放,游客参观该博物馆。夜间,游客前往城市 44。
  • 第 3 天:当前是一周中的第 3 天,游客位于城市 44。该城市的博物馆开放,游客参观该博物馆。夜间,游客前往城市 11。
  • 第 4 天:当前是一周中的第 1 天,游客位于城市 11。该城市的博物馆关闭。夜间,游客前往城市 22。
  • 第 5 天:当前是第 2 周的第 2 天,游客位于城市 22。该城市的博物馆开放,但游客此前已参观过。夜间,游客前往城市 33。
  • 第 6 天:当前是一周中的第 3 天,游客位于城市 33。该城市的博物馆开放,游客参观该博物馆。此后,旅行结束。

第二个样例的说明!

最多可参观的不同博物馆数量为 22。例如,可通过如下方式参观 22 个博物馆:

  • 第 1 天:当前是一周中的第 1 天,游客位于城市 11。该城市的博物馆开放,游客参观该博物馆。夜间,游客前往城市 22。
  • 第 2 天:当前是一周中的第 2 天,游客位于城市 22。该城市的博物馆关闭。夜间,游客前往城市 33。
  • 第 3 天:当前是一周中的第 3 天,游客位于城市 33。该城市的博物馆开放,游客参观该博物馆。此后,旅行结束。

输入解题思路,AI测评打分。不知道怎么写?

首页