# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
722761 | vjudge1 | Mostovi (COI14_mostovi) | C++14 | 4 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n;
bool visited[10002];
bool zabraneto[10002];
int kraj;
int most[10000];
bool dfs(int x)
{
visited[x]=true;
if (x==kraj) return true;
bool najde=false;
if (zabraneto[x]==false)
{
if (x<n && visited[x+1]==false) najde=dfs(x+1);
if (najde) return true;
if (x>n+1 && visited[x-1]==false) najde=dfs(x-1);
if (najde) return true;
}
if (most[x]>0 and visited[most[x]]==false) najde=dfs(most[x]);
return najde;
}
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')
{
if (max(b,c)<=n) zabraneto[min(b,c)]=true;
if (min(b,c)>=n-1) zabraneto[max(b,c)]=true;
}
if(a=='Q')
{
memset(visited,0,sizeof(visited));
kraj=c;
if(dfs(b))
cout<< "DA\n";
else cout<<"NE\n";
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |