Graph Theory

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1796    Accepted Submission(s):
750

Problem Description
Little Q loves playing with different kinds of graphs
very much. One day he thought about an interesting category of graphs called
``Cool Graph'', which are generated in the following way:
Let the set of
vertices be {1, 2, 3, ..., n

}. You have to consider every vertice from left to right (i.e. from vertice 2 to
n

). At vertice i

, you must make one of the following two decisions:
(1) Add edges between
this vertex and all the previous vertices (i.e. from vertex 1 to i−1

).
(2) Not add any edge between this vertex and any of the previous
vertices.
In the mathematical discipline of graph theory, a matching in a
graph is a set of edges without common vertices. A perfect matching is a
matching that each vertice is covered by an edge in the set.
Now Little Q is
interested in checking whether a ''Cool Graph'' has perfect matching. Please
write a program to help him.

 
Input
The first line of the input contains an integer T(1≤T≤50)

, denoting the number of test cases.
In each test case, there is an integer
n(2≤n≤100000)

in the first line, denoting the number of vertices of the graph.
The
following line contains n−1

integers a2,a3,...,an(1≤ai≤2)

, denoting the decision on each vertice.

 
Output
For each test case, output a string in the first line.
If the graph has perfect matching, output ''Yes'', otherwise output
''No''.
 
Sample Input
3
2
1
2
2
4
1 1 2
 
Sample Output
Yes
No
No
 
Source
 
Recommend
jiangzijing2015   |   We have carefully selected
several similar problems for you:  6286 6285 6284 6283 6282 
题意:给n个顶点,从第一个点开始操作,每个点有两种操作:1、将当前结点和之前的所有结点都加一条边 2、当前结点与之前的所有结点都不加边。问是否能够完美匹配?完美匹配是指所有的结点都有边连接,并且这些边中没有公共的顶点。
 
每一个2后面必须至少有一个1,那么倒着遍历
 
#include <iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<deque>
#include<vector>
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007;
using namespace std;
int a[];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
int s1=;
int s2=;
int x;
bool f=;
for(int i=;i<=n;i++)
{//2只能靠后面的1把它连上边 scanf("%d",&x);
a[i]=x;
}
for(int i=n;i>=;i--)//倒着遍历,从后往前看的话,1的数量一定要比2多
{
if(a[i]==) s1++;
else s2++;
if(s2>s1)
{
f=;
break;
}
}
if(n%==||!f||x!=) printf("No\n");//奇数个点肯定不行
else printf("Yes\n");
}
return ;
}

2017中国大学生程序设计竞赛 - 女生专场(Graph Theory)的更多相关文章

  1. 2017中国大学生程序设计竞赛 - 女生专场 Deleting Edges(思维+最短路)

    Deleting Edges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  2. 2017中国大学生程序设计竞赛 - 女生专场 Happy Necklace(递推+矩阵快速幂)

    Happy Necklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  3. 2017中国大学生程序设计竞赛 - 女生专场(dp)

    Building Shops Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) To ...

  4. 2017中国大学生程序设计竞赛 - 女生专场 1002 dp

    Building Shops Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  5. 2017中国大学生程序设计竞赛 - 女生专场C【前后缀GCD】

    C HDU - 6025 [题意]:去除数列中的一个数字,使去除后的数列中所有数字的gcd尽可能大. [分析]: 数组prefixgcd[],对于prefixgcd[i]=g,g为a[0]-a[i]的 ...

  6. 2017中国大学生程序设计竞赛 - 女生专场B【DP】

    B HDU - 6024 [题意]:n个教室,选一些教室建造糖果商店. 每个教室,有一个坐标xi和在这个教室建造糖果商店的花费ci. 对于每一个教室,如果这个教室建造糖果商店,花费就是ci,否则就是与 ...

  7. 2017中国大学生程序设计竞赛 - 女生专场A【模拟】

    A HDU - 6023 [题意]:求AC题数和总时长. [分析]:模拟.设置标记数组记录AC与否,再设置错题数组记录错的次数.罚时罚在该题上,该题没AC则不计入总时间,AC则计入.已经AC的题不用再 ...

  8. HDU 6024(中国大学生程序设计竞赛女生专场1002)

    这是CCPC女生专场的一道dp题.大佬们都说它简单,我并没有感到它有多简单. 先说一下题意:在一条直线上,有n个教室,现在我要在这些教室里从左到右地建设一些作为糖果屋,每个教室都有自己的坐标xi 和建 ...

  9. "巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场

    Combine String #include<cstdio> #include<cstring> #include<iostream> #include<a ...

随机推荐

  1. Angularjs注入拦截器实现Loading效果

    angularjs作为一个全ajax的框架,对于请求,如果页面上不做任何操作的话,在结果烦回来之前,页面是没有任何响应的,不像普通的HTTP请求,会有进度条之类. 什么是拦截器? $httpProvi ...

  2. 在数据库中添加数据以后,使用Mybatis进行查询结果为空

    在数据库中添加数据以后,使用Mybatis进行查询结果为空,这是因为数据库中添加数据忘记commit的缘故.

  3. selenium学习笔记(xpath和css定位)

    简单的介绍下xpath和css的定位 理论知识就不罗列了 还是利用博客园的首页.直接附上代码: 这个是xpath #!/usr/bin/env python # -*- coding: utf_8 - ...

  4. Oracle cmd乱码

    查看下环境变量的设置,查看是否有变量NLS_LANG,没有则新建该变量.新建变量,设置变量名:NLS_LANG,变量值根据以上字符集确定,一般都是中文简体SIMPLIFIED CHINESE_CHIN ...

  5. Python主流框架

    15个最受欢迎的Python开源框架.这些框架包括事件I/O,OLAP,Web开发,高性能网络通信,测试,爬虫等. Django: Python Web应用开发框架Django 应该是最出名的Pyth ...

  6. <img>边框的border属性

    默认地,图像是没有边框的(除非图像在 a 元素内部). 浏览器通常会把代表超链接的图像(例如包含在 <a> 标签中的图像)显示在两个像素宽的边框里面,以表示读者可以通过选择这个图像来访问相 ...

  7. 【河南省第十届ACM 省赛 A-谍报分析】

    题目描述 “八一三”淞沪抗战爆发后,*几次准备去上海前线视察和指挥作战.但都因为宁沪之间的铁路和公路遭到了敌军的严密封锁,狂轰滥炸,一直未能成行. 特科组织,其主要任务是保卫的安全,了解和掌握敌方的动 ...

  8. poj2446

    题解: 二分图匹配 看看是否能达到目标 代码: #include<cstdio> #include<cstring> #include<algorithm> #in ...

  9. 有了Docker的程序猿们就能开启“上帝视角”?

    现在,如果有程序猿说不知道Docker,这将是难以想象的. 百科是这样描述Docker的."Docker是dotCloud开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植 ...

  10. Leetcode 938. Range Sum of BST

    import functools # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, ...