#include <bits/stdc++.h>
using namespace std;
int n;
bool zab[1000][1000];
int most[1000000];
bool visited[1002];
bool proveri(int pocetok,int kraj)
{
queue<int> q;
q.push(pocetok);
visited[pocetok]=true;
while(!q.empty())
{
int poz=q.front();
//cout<<poz<<endl;
//system("pause");
q.pop();
if (poz==kraj) return true;
if (poz<n && visited[poz+1]==false && zab[poz][poz+1]==false)
{
q.push(poz+1);
visited[poz+1]=true;
}
if (poz>n-1 && visited[poz-1]==false && zab[poz][poz-1]==false)
{
q.push(poz-1);
visited[poz-1]=true;
}
if (most[poz]>0 && visited[most[poz]]==false && zab[poz][most[poz]]==false)
{
visited[most[poz]]=true;
q.push(most[poz]);
}
}
return false;
}
int main()
{
cin>>n;
int t;
cin>>t;
while(t--)
{
char a;
int b,c;
cin>>a>>b>>c;
if (a=='A')
{
most[b]=c;
most[c]=b;
}
if(a=='B')
{
zab[b][c]=true;
if (min(b,c)>n-1) zab[max(b,c)][min(b,c)]=true;
if (min(b,c)<n) zab[min(b,c)][max(b,c)]=true;
}
if(a=='Q')
{
memset(visited,0,sizeof(visited));
if(proveri(b,c))
cout<< "DA\n";
else cout<<"NE\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
3 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
4 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
5 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
6 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
7 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
8 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
9 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
10 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |