اگر جاوا یا ++C باشه که من بفهمم خب خیلی خوبه.
کدی که من خودم نوشتم و accept نشد رو هم اینجا میذارم شاید به درد بخوره...
<CODE>
#include <iostream>
#include <vector>
using namespace std;
void preprocess();
void read_input();
bool f(int source);
bool e[1001][1001];
bool marked[1001];
vector<int> neighbour[1001];
int N;
int M;
int x;
int y;
int z;
int w;
int main(){
int T;
cin>>T;
for(int i=0;i<T;i++){
cin>>N>>M;
preprocess();
read_input();
//masir az x be y mikhahim peyda konim ke z,w poshte sare ham bashand dar an
marked[x]=true;
bool b=f(x);
if(b==true){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}
return 0;
}
//dest y mibashad
bool f(int source){
if(source==y){
if(marked[z]==true && marked[w]==true){
return true;
}
return false;
}
if(source==z && marked[w]==false){
marked[w]=true;
bool b=f(w);
if(b==true){
return true;
}
marked[w]=false;
return false;
}
if(source==w && marked[z]==false){
marked[z]=true;
bool b=f(z);
if(b==true){
return true;
}
marked[z]=false;
return false;
}
vector<int> v=neighbour[source];
for(int i=0;i<v.size();i++){
int t=v[i];
if(e[source][t]==true){
if(marked[t]==false){
marked[t]=true;
bool b=f(t);
if(b==true){
return true;
}
marked[t]=false;
}
}
}
return false;
}
void read_input(){
int s,t;
for(int i=0;i<M;i++){
cin>>s>>t;
e[s][t]=true;
e[t][s]=true;
neighbour[s].push_back(t);
neighbour[t].push_back(s);
}
cin>>x>>y>>z>>w;
e[x][y]=false;
e[y][x]=false;
int F;
cin>>F;
for(int i=0;i<F;i++){
cin>>s>>t;
e[s][t]=false;
e[t][s]=false;
}
}
void preprocess(){
for(int i=1;i<N+1;i++){
marked[i]=false;
neighbour[i].clear();
}
}
</CODE>