#include <iostream>
#include <stack>
using namespace std;
int main(){
int husband;
int wife;
int a[200001];
int n;
while(1){
cin >> n;
if (n==0)
break;
for(int i=1;i<=n;i++){
cin >> husband >> wife;
a[husband]=i;
a[wife]=i;
}
stack <int> couples;
couples.push(a[1]);
//1.重点:采用STL的stack,需要包含头文件 #include <stack>
//2.重点:记住stack的基本函数 pop()、push()、empty()、top(}
for(int j=2;j<=2*n;j++){
if(!couples.empty()&& a[j]==couples.top())
couples.pop();
else
couples.push(a[j]);
}
if(!couples.empty())
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return 0;
}
1021. Couples
最新推荐文章于 2019-06-26 23:26:56 发布