CF2204D.Alternating Path
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an undirected graph with n vertices and m edges. The vertices are numbered from 1 to n. The graph contains no self-loops or multiple edges.
Your task is to make a graph directed by choosing a direction for each edge. After directing the edges, call a sequence of vertices v1,v2,…,vk, where k can be arbitrarily large and any vertex can be repeated any number of times, an alternating path if:
- the edge (v1,v2) is directed from v1 to v2;
- the edge (v2,v3) is directed from v3 to v2;
- the edge (v3,v4) is directed from v3 to v4;
- the edge (v4,v5) is directed from v5 to v4;
- and so on.
Call a vertex v beautiful if all paths (not necessarily simple) in the original graph that start at vertex v are alternating in the resulting directed graph.
What is the maximum number of vertices that can be made beautiful after directing the edges?
给你一个包含 n 个顶点和 m 条边的无向图。顶点编号为 1 到 n。该图不含自环或重边。
你的任务是通过为每条边指定一个方向,将该图转化为有向图。在完成边的定向后,称一个顶点序列 v1,v2,…,vk(其中 k 可任意大,且任意顶点可重复出现任意多次)为交替路径,如果满足:
- 边 (v1,v2) 的方向为从 v1 指向 v2;
- 边 (v2,v3) 的方向为从 v3 指向 v2;
- 边 (v3,v4) 的方向为从 v3 指向 v4;
- 边 (v4,v5) 的方向为从 v5 指向 v4;
- 依此类推。
称一个顶点 v 是优美的,如果在原图中所有从顶点 v 出发的路径(不一定是简单路径)在所得的有向图中均为交替路径。
在对边进行定向后,最多能有多少个顶点被设为优美的?
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line contains two integers n and m (1≤n≤2⋅105; 0≤m≤2⋅105) — the number of vertices and edges in the graph, respectively.
Each of the following m lines contains two integers v and u (1≤v,u≤n) — the description of the edges of the graph.
Additional constraints on the input:
- The given graph contains no self-loops or multiple edges;
- The sum of n over all test cases does not exceed 2⋅105;
- The sum of m over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
第一行包含两个整数 n 和 m(1≤n≤2⋅105;0≤m≤2⋅105),分别表示图中的顶点数和边数。
接下来的 m 行中,每行包含两个整数 v 和 u(1≤v,u≤n),表示图中的一条边。
输入的额外约束条件:
- 给定图中不含自环或重边;
- 所有测试用例的 n 值之和不超过 2⋅105;
- 所有测试用例的 m 值之和不超过 2⋅105。
输出格式
For each test case, print a single integer — the maximum number of vertices that can be made beautiful after directing the edges.
对于每个测试用例,输出一个整数——在对边进行定向后,能够变为“美丽”的顶点的最大数量。
输入输出样例
输入#1
4 8 9 1 3 1 4 2 3 2 4 5 6 6 7 7 8 8 5 6 8 4 0 6 2 1 5 2 3 1 0
输出#1
2 4 4 1
输入解题思路,AI测评打分。不知道怎么写?