A1105 | [COCI-2007_2008-contest1]#5 STAZA
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
A bicycle race is being organized in a country. The transport network of the country consists of N cities numbered 1 through N, with M bidirectional roads connecting them. We will use the following terms:
• A path is a sequence of roads in which each road starts in the city the preceding road ended in.
• A simple path is a path which never visits a city more than once.
• A ring is a simple path ending in the same city it started in.
The network is such that there is at least one path between every pair of cities. Additionally, every road in the network is part of at most one ring.
Your task is to find the longest path for the race satisfying two constraints:
• The path may begin in any city, but must end in city
1.
• The path may visit a city more than once, but it must not contain any road more than once.
• A path is a sequence of roads in which each road starts in the city the preceding road ended in.
• A simple path is a path which never visits a city more than once.
• A ring is a simple path ending in the same city it started in.
The network is such that there is at least one path between every pair of cities. Additionally, every road in the network is part of at most one ring.
Your task is to find the longest path for the race satisfying two constraints:
• The path may begin in any city, but must end in city
1.
• The path may visit a city more than once, but it must not contain any road more than once.
输入格式
The first line of input contains two integers N and M (2 ≤ N ≤ 10 000, 1 ≤ M ≤ 2N-2) – the numbers of cities and roads in the network.
Each of the following M lines contains two different integers A and B (1 ≤ A, B ≤ N). These numbers indicate that there is a bidirectional road between cities A and B. No two cities will be directly connected by more than one road.
Each of the following M lines contains two different integers A and B (1 ≤ A, B ≤ N). These numbers indicate that there is a bidirectional road between cities A and B. No two cities will be directly connected by more than one road.
输出格式
Output the length of the longest race path on a single line.
输入输出样例
输入 #1
4 3 1 2 1 3 2 4
输出 #1
2
输入 #2
6 6 1 2 1 3 2 4 3 4 3 5 5 6
输出 #2
5
输入 #3
5 6 1 2 2 3 3 4 4 5 5 3 3 1
输出 #3
6
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted