intgauss(int n){ int rank = 0; for (int c = 0, r = 0; c <= n; c++) { int t = r; for (int i = r; i <= n; i++) { if (abs(matrix[i][c]) > abs(matrix[t][c])) t = i; } if (abs(matrix[t][c]) < EPS) continue; if (t ^ r) swap(matrix[t], matrix[r]); for (int i = n + 1; i >= c; i--) matrix[r][i] /= matrix[r][c]; for (int i = 0; i <= n; i++) { if (abs(matrix[i][c]) > EPS && i ^ r) { for (int j = n + 1; j >= c; j--) { matrix[i][j] -= matrix[i][c] * matrix[r][j]; } } } r++; rank++; } for (int i = 0; i <= n; i++) voltage[i] = matrix[i][n + 1]; return2; }
voidout(int n){ cerr << "------------------" << endl; for (int i = 0; i <= n; i++) { for (int j = 0; j <= n + 1; j++) { cerr << fixed << setprecision(2) << setw(10) << matrix[i][j]; } cerr << endl; } cerr << "------------------" << endl; }
int n, m, k, q; cin >> n >> m >> k >> q; while (k--) { int u; cin >> u >> start[u]; } while (m--) { int u, v; double w; cin >> u >> v >> w; G[u].emplace_back(v, w); G[v].emplace_back(u, w); } matrix[0][0] = 1.0; for (int i = 1; i <= n; i++) { double sum = 0.0; if (abs(start[i]) > EPS) { matrix[i][i] = 1.0; matrix[i][n + 1] = start[i]; continue; } for (auto p: G[i]) { int u = p.first; matrix[i][u] += 1.0 / p.second; sum += 1.0 / p.second; } matrix[i][i] = -sum; } gauss(n); while (q--) { int u, v; cin >> u >> v; cout << fixed << setprecision(2) << voltage[u] - voltage[v] << endl; } return0; }