CF1494E.A-Z Graph

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a directed graph consisting of nn vertices. Each directed edge (or arc) labeled with a single character. Initially, the graph is empty.

You should process mm queries with it. Each query is one of three types:

  • " ++ uu vv cc " — add arc from uu to vv with label cc . It's guaranteed that there is no arc (u,v)(u, v) in the graph at this moment;
  • " - uu vv " — erase arc from uu to vv . It's guaranteed that the graph contains arc (u,v)(u, v) at this moment;
  • " ?? kk " — find the sequence of kk vertices v1,v2,,vkv_1, v_2, \dots, v_k such that there exist both routes v1v2vkv_1 \to v_2 \to \dots \to v_k and vkvk1v1v_k \to v_{k - 1} \to \dots \to v_1 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 nn and mm ( 2n21052 \le n \le 2 \cdot 10^5 ; 1m21051 \le m \le 2 \cdot 10^5 ) — the number of vertices in the graph and the number of queries.

The next mm lines contain queries — one per line. Each query is one of three types:

  • " ++ uu vv cc " ( 1u,vn1 \le u, v \le n ; uvu \neq v ; cc is a lowercase Latin letter);
  • " - uu vv " ( 1u,vn1 \le u, v \le n ; uvu \neq v );
  • " ?? kk " ( 2k1052 \le k \le 10^5 ).

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,,vkv_1, v_2, \dots, v_k 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=3k = 3 , we can, for example, choose a sequence [1,2,3][1, 2, 3] , since 1a2b31 \xrightarrow{\text{a}} 2 \xrightarrow{\text{b}} 3 and 3a2b13 \xrightarrow{\text{a}} 2 \xrightarrow{\text{b}} 1 .

In the second query of the third type k=2k = 2 , and we can't find sequence p1,p2p_1, p_2 such that arcs (p1,p2)(p_1, p_2) and (p2,p1)(p_2, p_1) have the same characters.

In the third query of the third type, we can, for example, choose a sequence [1,2,3,2,1][1, 2, 3, 2, 1] , where 1a2b3d2c11 \xrightarrow{\text{a}} 2 \xrightarrow{\text{b}} 3 \xrightarrow{\text{d}} 2 \xrightarrow{\text{c}} 1 .

首页