CF1494E.A-Z Graph
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a directed graph consisting of n vertices. Each directed edge (or arc) labeled with a single character. Initially, the graph is empty.
You should process m queries with it. Each query is one of three types:
- "+ u v c" — add arc from u to v with label c. It's guaranteed that there is no arc (u,v) in the graph at this moment;
- "− u v" — erase arc from u to v. It's guaranteed that the graph contains arc (u,v) at this moment;
- "? k" — find the sequence of k vertices v1,v2,…,vk such that there exist both routes v1→v2→⋯→vk and vk→vk−1→⋯→v1 and if you write down characters along both routes you'll get the same string. You can visit the same vertices any number of times.
给你一个包含 n 个顶点的有向图。每条有向边(或称弧)上标有一个单字符。初始时,该图为空。
你需要处理 m 个查询。每个查询为以下三种类型之一:
- “+ u v c” —— 添加一条从 u 到 v 的弧,其标签为 c。保证此时图中尚不存在弧 (u,v);
- “− u v” —— 删除从 u 到 v 的弧。保证此时图中存在弧 (u,v);
- “? k” —— 找出一个长度为 k 的顶点序列 v1,v2,…,vk,使得既存在路径 v1→v2→⋯→vk,也存在路径 vk→vk−1→⋯→v1,且沿这两条路径依次读取边上的字符所构成的字符串完全相同。允许重复访问同一顶点任意多次。
输入格式
The first line contains two integers n and m (2≤n≤2⋅105; 1≤m≤2⋅105) — the number of vertices in the graph and the number of queries.
The next m lines contain queries — one per line. Each query is one of three types:
- "+ u v c" (1≤u,v≤n; u=v; c is a lowercase Latin letter);
- "− u v" (1≤u,v≤n; u=v);
- "? k" (2≤k≤105).
It's guaranteed that you don't add multiple edges and erase only existing edges. Also, there is at least one query of the third type.
第一行包含两个整数 n 和 m(2≤n≤2⋅105;1≤m≤2⋅105)—— 分别表示图中顶点的数量和查询的数量。
接下来的 m 行每行包含一个查询,共三种类型:
- “+ u v c”(1≤u,v≤n;u=v;c 为一个小写拉丁字母);
- “− u v”(1≤u,v≤n;u=v);
- “? k”(2≤k≤105)。
保证不会添加重复的边,且仅删除已存在的边。此外,至少存在一个第三类查询。
输出格式
For each query of the third type, print YES if there exist the sequence v1,v2,…,vk described above, or NO otherwise.
对于每个第三种类型的查询,如果存在上述描述的序列 v1,v2,…,vk,则输出 YES;否则输出 NO。
输入输出样例
输入#1
3 11 + 1 2 a + 2 3 b + 3 2 a + 2 1 b ? 3 ? 2 - 2 1 - 3 2 + 2 1 c + 3 2 d ? 5
输出#1
YES NO YES
说明/提示
In the first query of the third type k=3, we can, for example, choose a sequence [1,2,3], since 1a2b3 and 3a2b1.
In the second query of the third type k=2, and we can't find sequence p1,p2 such that arcs (p1,p2) and (p2,p1) have the same characters.
In the third query of the third type, we can, for example, choose a sequence [1,2,3,2,1], where 1a2b3d2c1.
在第三个类型的第一次查询中,k=3,例如我们可以选择序列 [1,2,3],因为 1a2b3 且 3a2b1。
在第三个类型的第二次查询中,k=2,我们无法找到序列 p1,p2,使得弧 (p1,p2) 和 (p2,p1) 具有相同的字符。
在第三个类型的第三次查询中,例如我们可以选择序列 [1,2,3,2,1],其中 1a2b3d2c1。
输入解题思路,AI测评打分。不知道怎么写?