Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: patty
Problemset: Croissant Beyond Peaks
Language: cpp
Time: 0.007 second
Submitted On: 2026-02-26 10:56:15
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int q,n,countt;
cin >> q;
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
for(int i=0;i<q;i++) {
cin >> n;
vector<string> mp(2);
cin >> mp[0];
cin >> mp[1];
queue<pair<int,int>> qq;
vector<vector<bool>> visited(2,vector<bool>(n,false));
for(int j=0;j<2;j++) {
for(int k=0;k<n;k++) {
if(mp[j][k]=='S') {
countt=0;
qq.push({j,k});
visited[j][k]=true;
//cout << qq.front().first << " " << qq.front().second;
while(!qq.empty()) {
int a = qq.front().first;
int b = qq.front().second;
if(mp[a][b]=='T') countt+=1;
//cout << a << " " << b << " " << countt;
qq.pop();
for(int l=0;l<4;l++) {
int anext = a + dx[l];
int bnext = b + dy[l];
if(anext<0 || bnext<0 || anext>1 || bnext > n-1) continue;
if(mp[anext][bnext]=='#') continue;
//cout << anext << " " << bnext << "\n";
if(mp[anext][bnext]!='#' && visited[anext][bnext]==false) {
qq.push({anext,bnext});
visited[anext][bnext]=true;
//cout << "pass\n";
}
}
}
if(countt!=0) cout << "Yes\n";
else cout << "No\n";
}
}
}
}
}