SGU 174

SGU 174
ime Limit:1500MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Appoint description: 

Description

People of country T-land lived on the big plain many years ago. It is happened so that they started to quarrel, so they began to build walls to separate from each other. 
One day they realized that walls surround some part of the country. Your task is to determine which wall was build first to surround a part of the T-land.

Input

The first line of input contains one number M (1<=M<=200000) - number of walls. Each of the following M lines contains four integer numbers: Cartesian coordinates of two ends of each wall. Walls are rectilinear segments with positive length, two walls can cross only by ends, and walls can't coincide. All coordinates do not exceed 10^9 by its absolute values.

Output

Write the answer in the single line of output. If all the walls leave the territory opened, write 0.

Sample Input


Input
 
     
4 0 0 1 0 0 1 0 0 1 0 0 1 2 2 5 7
Output
 
     
3



用map建立映射,找点的下标

AC代码:
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <map>
using namespace std;

int fa[400005];
map< pair<int,int>,int >M;
int Find_set(int x)
{
    if(x==fa[x]) return x;
    fa[x]=Find_set(fa[x]);
    return fa[x];
}

int main()
{
    int m,x,y;
    int a,b,c,d;
    while(scanf("%d",&m)!=EOF)
    {
    for(int i=1;i<=400000;i++)
    fa[i]=i;
    int cnt=1;
    int flag=0;
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d%d",&a,&b,&c,&d);
        if(!flag)
        {
        if(!M.count(make_pair(a,b)))
        M[make_pair(a,b)]=cnt++;
        x=M[make_pair(a,b)];

        if(!M.count(make_pair(c,d)))
        M[make_pair(c,d)]=cnt++;
        y=M[make_pair(c,d)];

        int rx=Find_set(x);
        int ry=Find_set(y);
        if(rx==ry)
        flag=i;
        else
        fa[rx]=ry;
        }
    }
    printf("%d\n",flag);
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值