-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10503.cpp
More file actions
69 lines (65 loc) · 1.48 KB
/
Copy path10503.cpp
File metadata and controls
69 lines (65 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <vector>
#include <cstdio>
#define foi( i , n , k )for( int i = n ; i < k ; ++i)
using namespace std;
bool back(int pos,vector< pair<int,int> > &v,vector<bool>vp,pair<int,int> ini,pair<int,int>fin,int n)
{
if(pos==n)
return true;
if(pos==n-1)
{
// cout<<"entre -fin"<<endl;
foi( i , 0 , (int)v.size() )
{
if(vp[i])
{
vp[i]=false;
if(v[i].first==ini.second && (v[i].second==fin.first))
return true;
if(v[i].second==ini.second && (v[i].first==fin.first))
return true;
vp[i]=true;
}
}
return false;
}
else
{
// cout<<"entre "<<pos<<endl;
foi( i , 0 , (int)v.size() )
{
if( vp[i] && (v[i].first==ini.second||v[i].second==ini.second) )
{
vp[i]=false;
if(v[i].first==ini.second && back(pos+1,v,vp,v[i],fin,n))
return true;
if(v[i].second==ini.second && back(pos+1,v,vp,make_pair(v[i].second,v[i].first),fin,n) )
return true;
vp[i]=true;
}
}
}
return false;
}
int main()
{
int n,m;
while( scanf("%d",&n) != EOF && n!=0)
{
scanf("%d",&m);
pair<int,int> ini,fin;
scanf("%d%d%d%d",&ini.first,&ini.second,&fin.first,&fin.second);
vector< pair<int,int> > v(m);
vector<bool> vp(m,true);
foi( i , 0 , m )
{
scanf("%d%d",&v[i].first,&v[i].second);
}
if(back(0,v,vp,ini,fin,n))
printf("YES\n");
else
printf("NO\n");
}
return 0;
}