Initial commit: C++ courseware
This commit is contained in:
commit
4a4ee7c287
1789 files changed
+373489
No files matched your search
@@ -0,0 +1,34 @@
|
||||
// P2047 社交网络。正权、无向、简单、连通图;有序点对,排除端点。
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
using ll = long long;
|
||||
int main() {
|
||||
ios::sync_with_stdio(false); cin.tie(nullptr);
|
||||
int n, m; if (!(cin >> n >> m)) return 0;
|
||||
const ll INF = 1LL << 60;
|
||||
vector<vector<ll>> d(n, vector<ll>(n, INF));
|
||||
// 中间受限图的计数可能超过最终答案范围,从存储起即用浮点。
|
||||
vector<vector<long double>> cnt(n, vector<long double>(n, 0));
|
||||
for (int i = 0; i < n; ++i) d[i][i] = 0;
|
||||
for (int e = 0, u, v; e < m; ++e) {
|
||||
ll w; cin >> u >> v >> w; --u; --v;
|
||||
d[u][v] = d[v][u] = w; cnt[u][v] = cnt[v][u] = 1;
|
||||
}
|
||||
for (int k = 0; k < n; ++k) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
|
||||
if (i == k || j == k || i == j) continue;
|
||||
if (d[i][k] == INF || d[k][j] == INF) continue;
|
||||
ll nd = d[i][k]+d[k][j];
|
||||
long double ways = cnt[i][k]*cnt[k][j];
|
||||
if (nd < d[i][j]) { d[i][j] = nd; cnt[i][j] = ways; }
|
||||
else if (nd == d[i][j]) cnt[i][j] += ways;
|
||||
}
|
||||
cout << fixed << setprecision(3);
|
||||
for (int v = 0; v < n; ++v) {
|
||||
long double ans = 0;
|
||||
for (int s = 0; s < n; ++s) for (int t = 0; t < n; ++t) {
|
||||
if (s == t || s == v || t == v) continue;
|
||||
if (d[s][v]+d[v][t] == d[s][t]) ans += cnt[s][v]*cnt[v][t]/cnt[s][t];
|
||||
}
|
||||
cout << ans << '\n';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user