cf320b

来源:互联网 发布:大卫路易斯 知乎 编辑:程序博客网 时间:2024/06/07 03:39
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;int n;int cnt;int map_[110][110];class node{public:    int x,y;};int n1,n2;node no[110];int vis[110];bool dfs(int n){    vis[n]=1;    if(map_[n][n2]==1) return true;    for(int i=1; i<=cnt; i++)        if(map_[n][i] && !vis[i])        {            if(dfs(i)==1)//错误原因是写成“if(dfs(i)) return 1;else return 0;            return true;        }    return false;}int main(){    while(~scanf("%d",&n))    {        memset(map_,0,sizeof map_);        for(int i=0;i<=n;i++)            map_[i][i]=1;        cnt=0;        while(n--)        {            int t;            scanf("%d",&t);            if(t==1)            {                int x,y;                scanf("%d%d",&x,&y);                no[++cnt].x=x;                no[cnt].y=y;                for(int i=1; i<cnt; i++)                {                    if((no[i].x<y && no[i].x>x)||(no[i].y<y && no[i].y>x))                        map_[i][cnt]=1;                    if((no[i].x<y && no[i].y>y)||(no[i].x<x && no[i].y>x))                        map_[cnt][i]=1;                }            }            else            {                scanf("%d%d",&n1,&n2);                memset(vis,0,sizeof vis);                if(dfs(n1))                {                    map_[n1][n2]=1;                    printf("YES\n");                }                else                    printf("NO\n");            }        }    }    return 0;}/*201 1208 15831 -258 7291 -409 12011 194 19381 -958 15751 -1466 17522 1 22 1 22 6 51 -1870 18811 -2002 27491 -2002 29841 -2002 32932 2 42 8 102 9 6*/