版本比较
题解:P11562 【MX-X7-T3】[LSOT-3] 寄存器
正文
增加 8 行删除 8 行
36 行未改动373839404141424344454647484949505152525354555657585859606162636465666767686970707172737475767778787980818283848586868788899093 行未改动36 行未改动}
void dfs_for_sub1(int u, int fa) { vis[u] = 1; for(int to : G[u]) for(int to : G[u]) if(to != fa && all[to]) dfs_for_sub1(to, u);}
bool check(int S) { memset(vis, 0, sizeof vis); memset(all, 0, sizeof all); int ele = 0; for(int i = 0; i < n; i++) for(int i = 0; i < n; i++) if(S & (1 << i)) ele = i + 1, all[ele] = 1; dfs_for_sub1(ele, 0); for(int i = 1; i <= n; i++) for(int i = 1; i <= n; i++) if(all[i] && !vis[i]) return 0; return 1;}
bool equal() { for(int i = 1; i <= n; i++) for(int i = 1; i <= n; i++) if(a[i] != b[i]) return 0; return 1;}
int dfs(int dep, int &ans) { if(dep > 5) return 0; if(equal()) return ans = min(ans, dep - 1); for(int S : recov) { for(int i = 0; i < n; i++) for(int i = 0; i < n; i++) if(S & (1 << i)) b[i + 1] ^= 1; dfs(dep + 1, ans); for(int i = 0; i < n; i++) for(int i = 0; i < n; i++) if(S & (1 << i)) b[i + 1] ^= 1; } return 0;}
void Subtask1() { int ans = 5; for(int S = 1; S < (1 << n); S++) for(int S = 1; S < (1 << n); S++) if(check(S)) recov.push_back(S); dfs(1, ans); printf("%d\n", ans);}
void Subtusk2() { int root = 0, ans = 0, st = 0, en = 0, cnt = 0; for(int i = 1; i <= n; i++) for(int i = 1; i <= n; i++) if(deg[i] == 1) root = i; dfs_for_sub2(root, 0, st, en, cnt); if(!st) printf("0\n"); else if(cnt == 1) printf("%d\n", 1);93 行未改动