Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1796 Accepted Submission(s):
750
#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[100005]; int main() { int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); int s1=0; int s2=0; int x; bool f=1; for(int i=2;i<=n;i++) {//2只能靠后面的1把它连上边 scanf("%d",&x); a[i]=x; } for(int i=n;i>=2;i--)//倒着遍历,从后往前看的话,1的数量一定要比2多 { if(a[i]==1) s1++; else s2++; if(s2>s1) { f=0; break; } } if(n%2==1||!f||x!=1) printf("No\n");//奇数个点肯定不行 else printf("Yes\n"); } return 0; }
2017中国大学生程序设计竞赛 - 女生专场(Graph Theory)
原文:https://www.cnblogs.com/caiyishuai/p/9073702.html