Skip to content

Instantly share code, notes, and snippets.

@Rockbet
Created October 6, 2021 18:48
Show Gist options
  • Save Rockbet/7972a19d4674c7c64e0aa63e50bd45d0 to your computer and use it in GitHub Desktop.
Save Rockbet/7972a19d4674c7c64e0aa63e50bd45d0 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
bool pedra[maxn][maxn], visitado[maxn][maxn];
int n, m, sc, sl, rc, rl;
void dfs(int c, int l){
visitado[c][l] = 1;
for(int d=1; d<=3; d++){
// note que temos que checar se o vértice está dentro do lago,
// se ele ainda não foi visitado e se ele é uma pedra
if(c+d <= n and !visitado[c+d][l] and pedra[c+d][l]) dfs(c+d, l);
if(c-d >= 1 and !visitado[c-d][l] and pedra[c-d][l]) dfs(c-d, l);
if(l+d <= m and !visitado[c][l+d] and pedra[c][l+d]) dfs(c, l+d);
if(l-d >= 1 and !visitado[c][l-d] and pedra[c][l-d]) dfs(c, l-d);
}
}
int main(){
cin >> n >> m;
int p;
cin >> p;
for(int i=1; i<=p; i++){
int c, l;
cin >> c >> l;
pedra[c][l] = 1;
}
cin >> sc >> sl;
cin >> rc >> rl;
dfs(sc, sl);
if(visitado[rc][rl]) cout << "S\n";
else cout << "N\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment