Submission #722761

#TimeUsernameProblemLanguageResultExecution timeMemory
722761vjudge1Mostovi (COI14_mostovi)C++14
30 / 100
4 ms340 KiB
#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 timeMemoryGrader output
Fetching results...