CF813F.Bipartite Checking

省选/NOI-

通过率:0%

时间限制:6.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an undirected graph consisting of n vertices. Initially there are no edges in the graph. Also you are given q queries, each query either adds one undirected edge to the graph or removes it. After each query you have to check if the resulting graph is bipartite (that is, you can paint all vertices of the graph into two colors so that there is no edge connecting two vertices of the same color).

给你一个包含 nn 个顶点的无向图。初始时图中没有边。此外,你还会收到 qq 个查询,每个查询要么向图中添加一条无向边,要么删除一条无向边。每次查询后,你都需要判断当前图是否为二分图(即能否将图中所有顶点染成两种颜色,使得任意一条边所连接的两个顶点颜色不同)。

输入格式

The first line contains two integers n and q (2 ≤ n, q ≤ 100000).

Then q lines follow. _i_th line contains two numbers x__i and y__i (1 ≤ x__i < y__i ≤ n). These numbers describe _i_th query: if there is an edge between vertices x__i and y__i, then remove it, otherwise add it.

第一行包含两个整数 nn 和 qq(2 ≤ n, q ≤ 1000002 \le n, q \le 100000)。

接下来是 qq 行。第 ii 行包含两个数 xix_i 和 yiy_i(1 ≤ xi < yi ≤ n1 \le x_i < y_i \le n)。这些数描述了第 ii 个查询:如果顶点 xix_i 和 yiy_i 之间存在一条边,则将其删除;否则添加该边。

输出格式

Print q lines. _i_th line must contain YES if the graph is bipartite after _i_th query, and NO otherwise.

输出 q 行。第 i 行必须包含 YES(如果在第 i 次查询后该图是二分图),否则包含 NO。

输入输出样例

  • 输入#1

    3 5
    2 3
    1 3
    1 2
    1 2
    1 2

    输出#1

    YES
    YES
    NO
    YES
    NO

输入解题思路,AI测评打分。不知道怎么写?

首页