版本比较
题解:P13648 [NOISG 2016] Rock Climbing
正文
增加 5 行删除 5 行
18 行未改动19202122232425262728293031323334355 行未改动4142434445464748493 行未改动53545556575859606115 行未改动7778798081828384852 行未改动18 行未改动int v, c, nxt;node(int v = 0, int c = 0, int nxt = 0) : v(v), c(c), nxt(nxt) {}} e[MAXM << 1]; int head[MAXN], tot = 1;inlinevoid add(int u, int v, int c) {e[++tot] = node(v, c, head[u]), head[u] = tot;e[++tot] = node(u, 0, head[v]), head[v] = tot;}int lvl[MAXN], lst[MAXN];inlinebool bfs(int s, int t) {memset(lvl, 0xff, sizeof lvl);queue<int> q; q.emplace(s), lvl[s] = 0;for (int u; !q.empty(); ) {5 行未改动}return ~lvl[t];}inlineint dfs(int u, int t, int f) {if (u == t) return f; int res = 0;for (int &i = lst[u]; i; i = e[i].nxt) {int v = e[i].v, c = e[i].c;3 行未改动}return res;}inlineint dinic(int s, int t) {int res = 0;for (; bfs(s, t); res += dfs(s, t, inf));return res;15 行未改动for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) if (f[j][i]) f[j] |= f[i];}for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) if (f[i][j]) add(i, n + j, 1);}for (int i = 1; i <= n; i++) add(s, i, 1), add(n + i, t, 1);int res = n - dinic(s, t);printf("%d", res == n ? -1 : res + 1);2 行未改动18 行未改动19202122232425262728293031323334355 行未改动4142434445464748493 行未改动53545556575859606115 行未改动7778798081828384852 行未改动18 行未改动int v, c, nxt;node(int v = 0, int c = 0, int nxt = 0) : v(v), c(c), nxt(nxt) {}} e[MAXM << 1]; int head[MAXN], tot = 1;inlinevoid add(int u, int v, int c) {e[++tot] = node(v, c, head[u]), head[u] = tot;e[++tot] = node(u, 0, head[v]), head[v] = tot;}int lvl[MAXN], lst[MAXN];inlinebool bfs(int s, int t) {memset(lvl, 0xff, sizeof lvl);queue<int> q; q.emplace(s), lvl[s] = 0;for (int u; !q.empty(); ) {5 行未改动}return ~lvl[t];}inlineint dfs(int u, int t, int f) {if (u == t) return f; int res = 0;for (int &i = lst[u]; i; i = e[i].nxt) {int v = e[i].v, c = e[i].c;3 行未改动}return res;}inlineint dinic(int s, int t) {int res = 0;for (; bfs(s, t); res += dfs(s, t, inf));return res;15 行未改动for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) if (f[j][i]) f[j] |= f[i];}for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) if (f[i][j]) add(i, n + j, 1);}for (int i = 1; i <= n; i++) add(s, i, 1), add(n + i, t, 1);int res = n - dinic(s, t);printf("%d", res == n ? -1 : res + 1);2 行未改动