欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF919D.Substring
Substring
Statement
You are given a graph with nodes and directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if letters on a path are "abaca", then the value of that path is . Your task is find a path whose value is the largest.
Input
The first line contains two positive integers (), denoting that the graph has nodes and directed edges. The second line contains a string with only lowercase English letters. The -th character is the letter assigned to the -th node. Then lines follow. Each line contains two integers (), describing a directed edge from to . Note that can be equal to and there can be multiple edges between and . Also the graph can be not connected.
Output
Output a single line with a single integer denoting the largest value. If the value can be arbitrarily large, output -1 instead.
样例
样例 1
输入:
5 4
abaca
1 2
1 3
3 4
4 5
输出:
3
样例 2
输入:
6 6
xzyabc
1 2
3 1
2 3
5 4
4 3
6 4
输出:
-1
样例 3
输入:
10 14
xzyzyzyzqx
1 2
2 4
3 5
4 5
2 6
6 8
6 5
2 10
3 9
10 9
4 6
1 10
2 8
3 7
输出:
4
样例解释(英文原文)
In the first sample, the path with largest value is . The value is because the letter 'a' appears times.
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |