1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| typedef pair<int, int> PII; const int maxn = 210, maxm = (210 + 210 + 210*210) * 2; const int inf = 0x3f3f3f3f; const double eps = 1e-5;
int head[maxn], ver[maxm], e[maxm], ne[maxm], idx = 1; int n, S = 0, T, tot = 0; double D; PII ice[maxn];
void add(int a, int b, int c) { ver[++idx] = b; e[idx] = c; ne[idx] = head[a]; head[a] = idx; ver[++idx] = a; e[idx] = 0; ne[idx] = head[b]; head[b] = idx; }
bool check(const PII &a, const PII &b) { double dx = a.first - b.first, dy = a.second - b.second; return dx*dx + dy*dy <= D*D + eps; }
void init() { memset(head, 0, sizeof head); idx = 1; tot = 0; }
int d[maxn], cur[maxn]; bool bfs() { memset(d, -1, sizeof d); d[S] = 0, cur[S] = head[S]; queue<int> q; q.push(S); while (q.size()) { int x = q.front(); q.pop(); for (int i = head[x]; i; i = ne[i]) { int y = ver[i]; if (d[y] == -1 && e[i]) { d[y] = d[x] + 1; cur[y] = head[y]; if (y == T) return true; q.push(y); } } } return false; }
int dinic(int u, int lim) { if (u == T) return lim; int flow = 0; for (int i = cur[u]; i && lim > flow; i = ne[i]) { cur[u] = i; int v = ver[i]; if (d[v] == d[u] + 1 && e[i]) { int t = dinic(v, min(e[i], lim - flow)); if (!t) d[v] = -1; flow += t, e[i] -= t, e[i^1] += t; } } return flow; }
int dinic() { int res = 0, flow; while (bfs()) while (flow = dinic(S, inf)) res += flow; return res; }
void solve() { int cnt = 0; for (int i = 1; i <= n; i++) { T = i; for (int k = 2; k <= idx; k += 2) { e[k] += e[k^1]; e[k^1] = 0; } int res = dinic(); if (res == tot) { cnt++; printf("%d ", i-1); } } if (cnt == 0) printf("-1\n"); else printf("\n"); }
int main() { freopen("input.txt", "r", stdin); int kase; cin >> kase; while (kase--) { init(); scanf("%d%lf", &n, &D); S = 0; // ice for (int i = 1; i <= n; i++) { int x, y, _n, _m; scanf("%d%d%d%d", &x, &y, &_n, &_m); ice[i] = {x, y}; add(i, n+i, _m); add(S, i, _n); tot += _n; } // link node for (int i = 1; i <= n; i++) for (int j = i+1; j <= n; j++) { if (check(ice[i], ice[j])) { add(n+i, j, inf); add(n+j, i, inf); } }
// then solve solve(); } }
|