Graph Theory

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

                                                                                                             Total Submission(s): 17    Accepted Submission(s): 10

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




—————————————————————— ————————————

题意:有n个点,每个点有两种连边方式,1表示和前面所有的点连边,2表示和前面所有的点不连边,问能不能构成完美匹配

解题思路:若n为奇数,则不可能;n为偶数时,从后向前判,看方式1的个数是否一直大于方式2

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <functional> using namespace std; #define LL long long
const int INF=0x3f3f3f3f; int a[100005]; int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=1; i<n; i++)
scanf("%d",&a[i]);
if(n%2)
{
printf("No\n");
}
else
{
int cnt=0;
int flag=0;
for(int i=n-1; i>=1; i--)
{
if(a[i]==1)
cnt++;
else
{
if(cnt==0)
{
flag=1;
break;
}
cnt--;
}
}
if(flag) printf("No\n");
else printf("Yes\n");
}
}
return 0;
}



HDU6029 Graph Theory 2017-05-07 19:04 40人阅读 评论(0) 收藏的更多相关文章

  1. HDU6026 Deleting Edges 2017-05-07 19:30 38人阅读 评论(0) 收藏

    Deleting Edges                                                                                  Time ...

  2. cubieboard变身AP 分类: ubuntu cubieboard 2014-11-25 14:04 277人阅读 评论(0) 收藏

    加载bcmdhd模块:# modprobe bcmdhd 如果你希望开启 AP 模式,那么:# modprobe bcmdhd op_mode=2 在/etc/modules文件内添加bcmdhd o ...

  3. HDU6029 Happy Necklace 2017-05-07 19:11 45人阅读 评论(0) 收藏

    Happy Necklace                                                                           Time Limit: ...

  4. 滑雪 分类: POJ 2015-07-23 19:48 9人阅读 评论(0) 收藏

    滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 83276 Accepted: 31159 Description Mich ...

  5. iOS开发之监听键盘高度的变化 分类: ios技术 2015-04-21 12:04 233人阅读 评论(0) 收藏

    最近做的项目中,有一个类似微博中的评论转发功能,屏幕底端有一个输入框用textView来做,当textView成为第一响应者的时候它的Y值随着键盘高度的改变而改变,保证textView紧贴着键盘,但又 ...

  6. POJ3320 Jessica's Reading Problem 2017-05-25 19:55 38人阅读 评论(0) 收藏

    Jessica's Reading Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12346   Accep ...

  7. HDU6027 Easy Summation 2017-05-07 19:02 23人阅读 评论(0) 收藏

    Easy Summation                                                             Time Limit: 2000/1000 MS ...

  8. POJ1269 Intersecting Lines 2017-04-16 19:43 50人阅读 评论(0) 收藏

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15478   Accepted: 67 ...

  9. Making the Newsfeed web part available outside of My Sites in SharePoint 2013 分类: Sharepoint 2015-07-07 19:29 4人阅读 评论(0) 收藏

    The Newsfeed is a key piece in SP2013's approach to social computing. It appears on the landing page ...

随机推荐

  1. 迷你MVVM框架 avalonjs 学习教程19、avalon历史回顾

    avalon最早发布于2012.09.15,当时还只是mass Framework的一个模块,当时为了解决视图与JS代码的分耦,参考knockout开发出来. 它的依赖收集机制,视图扫描,绑定的命名d ...

  2. js 日期证有效性验的通用方法

    开发的理念是“为复用而开发,为使用而组装”,代码的复用度将是项目和产品的一个重要的技术指标. var DateTools={ isDate:function(str) { var result = s ...

  3. Javascript 函数传参问题

    属于传值,不能改变参数的属性 example 1  function Myvalue(){ var arry = 5; return arry ; } document.getElementById( ...

  4. CentOS7使用yum详细搭建zabbix3.2过程

    本文引用于:http://blog.csdn.net/s3275492383/article/details/62417210 一.准备搭建环境: 1.系统:CentOS7 2.默认有使用linux服 ...

  5. jps command not found已解决

    根据当前版本安装devel 包 eg: yum install java--openjdk-devel -y jdk小工具jps介绍 jps(Java Virtual Machine Process ...

  6. IDEA artifacts Web Application:Exploded Web Application:Archive

    首先,artifacts是maven中的一个概念,表示项目/modules如何打包,比如jar,war,war exploded,ear等打包形式,一个项目或者说module有了artifacts 就 ...

  7. Enterprise Library 企业库

    微软企业库,提供了一套日志,缓存等功能的库.可以通过NuGet安装.

  8. selenium IDE常用命令

    1.open(URL)命令                 1.作用:打开指定的URL,URL或者为相对或是绝对的URL                 2.target:要打开的URL,value值 ...

  9. 通过阿里OSS文件服务返回的URL获取文件流下载

    我们都知道将文件上传到阿里的OSS文件服务上后,可以通过generatePresignedUrl(bucketName, key, expiration)方法获取该文件的防问路径,但是当我们知道该文件 ...

  10. 指针c艹

    #include <iostream> using namespace std;int value=1;void func(int *p){ p=&value; }void fun ...