您的位置:首页 > 新闻 > 资讯 > 在线制作印章生成免费_编程语言有哪些_西安百度公司开户_企业营销策划方案范文

在线制作印章生成免费_编程语言有哪些_西安百度公司开户_企业营销策划方案范文

2025/7/1 10:21:56 来源:https://blog.csdn.net/2301_79470071/article/details/146999265  浏览:    关键词:在线制作印章生成免费_编程语言有哪些_西安百度公司开户_企业营销策划方案范文
在线制作印章生成免费_编程语言有哪些_西安百度公司开户_企业营销策划方案范文

E - Replace(判环,破环成链)

#include <bits/stdc++.h>
#include <atcoder/dsu>using namespace std;
using namespace atcoder;const int C = 26;int main() {int n;cin >> n;string s, t;cin >> s >> t;if (s == t) {cout << 0 << endl;return 0;}vector<int> to(C, -1);for (int i = 0; i < n; i++) {int sc = s[i] - 'a';int tc = t[i] - 'a';if (to[sc] != -1 and to[sc] != tc) {cout << -1 << endl;return 0;}to[sc] = tc;}bool is_perm = true;vector<int> tmp = to;sort(tmp.begin(), tmp.end());for (int i = 0; i < C; i++) {is_perm &= (tmp[i] == i);}if (is_perm) {cout << -1 << endl;return 0;}int ans = 0;vector<int> in_deg(C);dsu uf(C);for (int i = 0; i < C; i++) {if (to[i] != -1) {if (to[i] != i) {ans++;}in_deg[to[i]]++;uf.merge(i, to[i]);}}vector<vector<int>> groups = uf.groups();for (const vector<int> &g: groups) {bool is_cycle = true;for (int i: g) {is_cycle &= (in_deg[i] == 1);}if (is_cycle and g.size() > 1) {ans++;}}cout << ans << endl;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com