C Inkuvi
C Inkuvi
h>
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, m;
string s;
cin >> s;
int L = n + m - 1;
int r = 0, c = 0;
path.push_back({r, c});
for (auto ch : s) {
else c++;
path.push_back({r, c});
if (!onPath[i][j]) {
fixedRow[i] += grid[i][j];
fixedCol[j] += grid[i][j];
int V = n + m;
int E = L;
auto pr = path[i];
adj[u].push_back({v, i});
adj[v].push_back({u, i});
}
deg[i] = adj[i].size();
queue<int> qu;
if (deg[i] == 1) {
qu.push(i);
inQueue[i] = true;
while (!qu.empty()) {
int u = qu.front();
qu.pop();
if (!usedEdge[p.second]) {
nei = p.first;
eid = p.second;
break;
edgeVal[eid] = B[u];
usedEdge[eid] = true;
removed[u] = true;
deg[u]--;
deg[nei]--;
B[nei] -= edgeVal[eid];
qu.push(nei);
inQueue[nei] = true;
auto pr = path[i];
grid[pr.first][pr.second] = edgeVal[i];
}
}
return 0;