CF1494E.A-Z Graph
普及/提高-
通过率:0%
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.
输入格式
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.
输出格式
For each query of the third type, print YES if there exist the sequence v1,v2,…,vk described above, or NO otherwise.
输入输出样例
输入#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 .