题意:有n个点,对于每个点有两种操作,(1) 跟他之前的点都连一条边。(2) 不做操作。现在对于每个点都给定了操作,问能否从中选取几条边,每条边都没有公共端点,而且n个点都被边覆盖。
分析:首先,很容易想到,当n为奇数的时候,答案肯定是No。
然后是偶数,取一个cnt表示到当前,前面还有几个点没有连边,for一遍就好。
以下是代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstring>
#include<string>
#include<vector>
#include<iomanip>
//#include<unordered_set>
//#include<unordered_map>
#include<cmath>
#include<list>
#include<bitset>
using namespace std;
#define _____ ios::sync_with_stdio(false); cin.tie(0);
#define ull unsigned long long
#define ll long long
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
typedef pair<int, int>pii;
typedef pair<ll, ll>pll;
typedef pair<double, double>pdd;
const double eps = 1e-6;
const int MAXN = 100005;
const int MAXM = 5005;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const double FINF = 1e18;
const ll MOD = 1000000007;
int a[100005];
int main()
{
int t,n;
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
if (n % 2 == 1)
{
for (int i = 2; i <= n; ++i)scanf("%d", &a[i]);
printf("No\n");
}
else
{
int cnt = 1;
bool flag = 1;
for (int i = 2; i <= n; ++i)
{
scanf("%d", &a[i]);
if (a[i] == 1)
{
if (cnt == 0)cnt = 1;
else cnt--;
}
else cnt++;
}
if (cnt > 0)printf("No\n");
else printf("Yes\n");
}
}
}