URAL 1966 cycling Roads points on line segments, line segments intersect, and look up sets

Source: Internet
Author: User

f-cycling Roads

Description

When Vova is in Shenzhen, he rented a bike and spent most of the time cycling around the city. Vova was approaching one of the city parks when he noticed the park plan hanging opposite the central entrance. The plan had several marble statues marked on it. One of such statues stood right there, by the park entrance. Vova wanted to ride in the park on the bike and take photos of all statues. The park territory has multiple bidirectional cycling roads. Each cycling road starts and ends at a marble statue and can is represented as a segment on the plane. If The cycling roads share a common point and then Vova can turn on this point from one road to the other. If The statue stands right on the road, it doesn ' t interfere with the traffic in any-and can be-photoed from the road. Can Vova get statues in the park riding he bike along cycling roads only?

Input

The first line contains integers Nand mThat is the number of statues and cycling roads in the park (1≤ m< N≤200). Then NLines follow, each of the them contains the coordinates of one statue on the park plan. The coordinates is integers, their absolute values don ' t exceed 30 000. Any of the statues has distinct coordinates. Each of the following mLines contains-distinct integers from 1 to NThat is the numbers of the statues that has a cycling road between them.

Output

Print "YES" if Vova can get from the park entrance to all the park statues, moving along cycling roads only, and "NO" othe Rwise.

Sample Input

input Output
4 20 01 01 10 11 34 2
YES

Test instructions

Here you are, N.

Here you are, M-line.

Ask if you have a connection.

Exercises

Point on the line segment, whether the segment intersects the board to determine

Join a collection of connected points

Finally, determine if all the points are in a set inside

#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<vector>#include<algorithm>using namespacestd;Const intN = 5e4+ -, M = 1e2+Ten, mod = 1e9+7, INF = 1e9+ +; typedefLong Longll;Const DoubleINF =1E200;Const DoubleEP = 1e-Ten;Const intMAXV =30000;Const DoublePI =3.14159265;structpoint{Doublex;Doubley; Point (DoubleA=0,Doubleb=0) {x=a; y=b;}//ConstructorPointoperator- (ConstPoint &b)Const {    returnPoint (x-b.x, Y-b.y); }  Double operator^ (ConstPoint &b)Const {    returnx*b.y-y*b.x;}};structline{point S; Point e; Line (Point A, point B) {s=a; E=b;} Line () {}};intSgnDoublex) {if(Fabs (x) < EP)return 0;if(X <0)return-1;Else return 1;}BOOLInter (line L1,line L2) {returnMax (l1.s.x,l1.e.x)>= min (l2.s.x,l2.e.x) &&Max (l2.s.x,l2.e.x)>= min (l1.s.x,l1.e.x) &&Max (L1.S.Y,L1.E.Y)>= min (l2.s.y,l2.e.y) &&Max (L2.S.Y,L2.E.Y)>= min (l1.s.y,l1.e.y) &&SGN (L2.s-L1.E) ^ (L1.S-L1.E)) *SGN ((l2.e-l1.e) ^ (L1.S-L1.E)) <=0&&SGN (L1.s-L2.E) ^ (L2.S-L2.E)) *SGN ((l1.e-l2.e) ^ (L2.S-L2.E)) <=0;}BOOLonseg (Point P, line L) {returnSGN (L.s-p) ^ (l.e-p)) = =0&&SGN (p.x-l.s.x) * (p.x-l.e.x)) <=0&&SGN (p.y-L.S.Y) * (P.Y-L.E.Y)) <=0;}//intersectionPoint p[n]; Line Dg[n];intN,m,posa[n],posb[n],fa[n],cnt,vis[n];intFindsintx) {returnx==fa[x]?x:fa[x]=finds (Fa[x]);}voidUnions (intXinty) {intFX =finds (x); intFY =finds (Y); if(FX! = FY) Fa[fx] =fy;}intMain () {scanf ("%d%d",&n,&m);  for(intI=1; i<=n;i++) Fa[i] =i;  for(intI=1; i<=n;i++) {        Doublex, y; scanf ("%LF%LF",&x,&y); P[i]=(point) {x, y}; }     for(intI=1; i<=m;i++) {scanf ("%d%d",&posa[i],&Posb[i]);        Unions (Posa[i],posb[i]); Dg[i]=(line) {p[posa[i]],p[posb[i]]}; }//Point on the line segment      for(intI=1; i<=n;i++) {         for(intj=1; j<=m;j++) {            if(Onseg (P[i],dg[j])) {unions (i,posa[j]);            Unions (I,POSB[J]); }}}, point pp;//Segment Intersection     for(intI=1; i<=m;i++) {         for(intj=1; j<=m;j++) {            if(Inter (Dg[i],dg[j])) {unions (posa[i],posa[j]);                Unions (POSA[I],POSB[J]);                Unions (POSB[I],POSA[J]);            Unions (POSB[I],POSB[J]); }        }    }    intall =1; intfi = Finds (1);  for(intI=1; i<=n;i++) {        if(Finds (i)! =FI) {Puts ("NO");return 0; }} puts ("YES");}

URAL 1966 cycling Roads points on line segments, line segments intersect, and look up sets

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.