版本比较
题解:P14906 [NHSPC 2024] 数字丛集
正文
增加 8 行删除 8 行
29 行未改动303132333435363738394041424344454647484950515253545556575859606162638 行未改动7273747576777879806 行未改动29 行未改动int x = find(c1), y = find(c2);if (x != y) {fa[x] = y;}}//并查集模板bool P(string a, string b) {if (a.size() > b.size()) {swap(a, b);}int la = a.size(), lb = b.size();while (la < lb) {a = '0' + a;la++;}int sum = 0;//不同的数位的个数char x = '#', y = '#';//a, b 中第一个不同的for (int i = 0; i < la; i++) {if (a[i] != b[i]) {sum++;if (x != '#') {//如果已经选过if (a[i] != y || b[i] != x) {//交换后是否合法return 0;}} else {x = a[i];y = b[i];}}}return sum == 2;//sum = 2 才合法}signed main() {cin >> n;for (int i = 1; i <= n; i++) {8 行未改动}}for (int i = 1; i <= n; i++) {cnt[find(i)]++;}for (int i = 1; i <= n; i++) {if (cnt[i]) {ans1++;ans2 = max(ans2, cnt[i]);6 行未改动29 行未改动303132333435363738394041424344454647484950515253545556575859606162638 行未改动7273747576777879806 行未改动29 行未改动int x = find(c1), y = find(c2);if (x != y) {fa[x] = y;}}//并查集模板bool P(string a, string b) {if (a.size() > b.size()) {swap(a, b);}int la = a.size(), lb = b.size();while (la < lb) {a = '0' + a;la++;}int sum = 0;//不同的数位的个数char x = '#', y = '#';//a, b 中第一个不同的for (int i = 0; i < la; i++) {if (a[i] != b[i]) {sum++;if (x != '#') {//如果已经选过if (a[i] != y || b[i] != x) {//交换后是否合法return 0;}} else {x = a[i];y = b[i];}}}return sum == 2;//sum = 2 才合法}signed main() {cin >> n;for (int i = 1; i <= n; i++) {8 行未改动}}for (int i = 1; i <= n; i++) {cnt[find(i)]++;}for (int i = 1; i <= n; i++) {if (cnt[i]) {ans1++;ans2 = max(ans2, cnt[i]);6 行未改动