#pragma GCC optimize(2) usingnamespace std; #define ll long long #define PII pair<int,int> #define PLL pair<ll,ll> #define fi first #define se second #define pb push_back #define debug(a) cout << #a << " " << a << '\n'; constint N = 1e5 + 5; constint M = 1e5 + 5; constint INF = 0x3f3f3f3f; const ll LLINF = 0x3f3f3f3f3f3f3f3f; const ll mod = 1e9 + 7;
inline ll read();
int n, m; #define ll long long #define INF 0x3f3f3f3f constint maxn = 205; char a[maxn][maxn], b[maxn][maxn], c[maxn][maxn]; int cnt = 0; map<pair<int, int>, int> ma; vector<pair<int, int> > save1, save2; bool ok = 0;
voidcheck(){ save1.clear(); int mnr = INF, mnc = INF; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { if (c[i][j] == '#') { save1.push_back({i, j}); mnr = min(mnr, i); mnc = min(mnc, j); } } for (int i = 0; i < save1.size(); i++) { save1[i].first -= mnr; save1[i].second -= mnc; } if (save1.size() != save2.size())return; for (auto it: save1) { if (!ma[it])return; }
ok = 1; }
voidsolve(){ cin >> n; int mnr = INF, mnc = INF; for (int i = 1; i <= n; i++)for (int j = 1; j <= n; j++)cin >> a[i][j], c[i][j] = a[i][j]; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { cin >> b[i][j]; if (b[i][j] == '#') { save2.push_back({i, j}); mnr = min(mnr, i); mnc = min(mnc, j);//找到最左上角的那个# } } for (int i = 0; i < save2.size(); i++) { save2[i].first -= mnr;//将所有#向左上角移 save2[i].second -= mnc; ma[save2[i]] = 1; } for (int u = 0; u < 4; u++) { for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { c[j][n - i + 1] = a[i][j]; } for (int i = 1; i <= n; i++)for (int j = 1; j <= n; j++)a[i][j] = c[i][j]; check(); }
}
intmain(){ solve(); if (ok)puts("Yes"); elseputs("No"); return0; }
ll res = 0, cnt = 0; for (int i = 0; i < m; i++) { int a = edges[i].a, b = edges[i].b, w = edges[i].w;
a = find(a), b = find(b); if (a != b)//找到的祖宗不相等说明不连通 { p[a] = b; res += w; cnt++; } else { if (w < 0)res += w; } }
return res; }
intmain(){ ll sum = 0; scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { int a, b, w; scanf("%d%d%d", &a, &b, &w); edges[i] = {a, b, w}; sum += w; }
#pragma GCC optimize(2) usingnamespace std; #define ll long long #define PII pair<int,int> #define PIII pair<pair<int,int>,int> #define PLL pair<ll,ll> #define fi first #define se second #define pb push_back #define debug(a) cout << #a << " " << a << '\n'; constint N = 500; constint M = 1e5 + 5; constint INF = 0x3f3f3f3f; const ll LLINF = 0x3f3f3f3f3f3f3f3f; const ll mod = 1e9 + 7;
inline ll read();
int n, m; vector<int> g[N*N]; int dis[N], dis2[N]; int pre[N]; bool st[N*N]; map<PII, int> mp; map<int, PII > mp2;
voidbfs(){ memset(dis,-1,sizeof dis); queue<int> q; dis[1] = 0; q.push(1); while (!q.empty()) { int t = q.front();
q.pop(); for (int i = 0; i < g[t].size(); i++) { int j = g[t][i]; if (dis[j]!=-1)continue; dis[j] = dis[t] + 1; pre[j] = t; //cout<<j<<' '<<t<<'\n'; q.push(j); } } }
voidbfs2(int x, int y){ queue<int> q; dis2[1] = 0; q.push(1); while (!q.empty()) { int t = q.front();
q.pop(); for (int i = 0; i < g[t].size(); i++) { int j = g[t][i]; if (t == x && j == y)continue; if (dis2[j] != -1)continue; dis2[j] = dis2[t] + 1; q.push(j); } } }
intmain(){ //ios::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; g[a].pb(b); mp[{a, b}] = i; mp2[i] = {a, b}; } bfs(); int now = n; while (true) { if (mp[{pre[now], now}]) { st[mp[{pre[now], now}]] = true;//标记有效边
} now = pre[now]; if (now == 1 || !now)break; }
for (int i = 1; i <= m; i++) { if (!st[i])cout << dis[n] << '\n'; else { memset(dis2, -1, sizeof dis2); int x = mp2[i].fi; int y = mp2[i].se; bfs2(x, y);
cout << dis2[n] << '\n'; } }
return0; }
inline ll read(){ char ch = getchar(); ll p = 1, data = 0; while (ch < '0' || ch > '9') { if (ch == '-')p = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { data = data * 10 + (ch ^ 48); ch = getchar(); } return p * data; }