QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#398317 | #3770. Minimum Spanning Tree | SamponYW# | AC ✓ | 565ms | 10212kb | C++14 | 2.1kb | 2024-04-25 10:47:01 | 2024-04-25 10:47:02 |
Judging History
answer
#include <bits/stdc++.h>
#define db double
#define il inline
#define re register
#define ll long long
#define ui unsigned
#define ull ui ll
#define i128 __int128
#define pii pair<int, int>
#define fi first
#define se second
#define eb emplace_back
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(), v.end()
#define mems(v, x) memset(v, x, sizeof(v))
#define memc(a, b) memcpy(a, b, sizeof(a))
#define FOR(i, L, R) for(re int i = (L); i <= (R); ++i)
#define ROF(i, R, L) for(re int i = (R); i >= (L); --i)
#define LS i << 1, l, mid
#define RS i << 1 | 1, mid + 1, r
#define popc(x) __builtin_popcount(x)
using namespace std;
#define N 200005
#define P 1000000007
il int add(int x, int y) {return x + y < P ? x + y : x + y - P;}
il void addr(int &x, int y) {(x += y) >= P && (x -= P);}
il int qpow(int p, int n = P - 2) {
int s = 1;
while(n) {
if(n & 1) s = 1ll * s * p % P;
p = 1ll * p * p % P, n >>= 1;
}
return s;
}
const int mu = qpow(1e4);
int n, m, L, R;
struct edge {
int u, v, a, b;
} e[N];
ll w[N]; int p[N], f[N];
il int F(int x) {return f[x] ^ x ? f[x] = F(f[x]) : x;}
il ll calc(int mid) {
// cerr << mid << "\n";
FOR(i, 1, n) f[i] = i;
FOR(i, 1, m) w[i] = e[i].a + 1ll * mid * e[i].b, p[i] = i;
sort(p + 1, p + 1 + m, [](int x, int y) {return w[x] < w[y];});
ll ns = 0;
FOR(t, 1, m) {
int i = p[t];
int x = F(e[i].u), y = F(e[i].v);
if(x ^ y) f[y] = x, ns += w[i];
}
return ns;
}
il void WORK() {
FOR(i, 1, m) {
auto &[u, v, a, b] = e[i];
cin >> u >> v >> a >> b;
}
ll ans = 1e18;
// while(L < R) {
// int mid = (L + R) >> 1;
// ll A = calc(mid), B = calc(mid + 1);
// if(A > B) ans = min(ans, B), L = mid + 1;
// else ans = min(ans, A), R = mid - 1;
// }
// while(L <= R) ans = min(ans, calc(L++));
// cout << ans << "\n";
cout << min(calc(L), calc(R)) << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
while(cin >> n >> m >> L >> R) WORK();
cerr << 1.0 * clock() / CLOCKS_PER_SEC;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 565ms
memory: 10212kb
input:
5 6 1 5 1 2 3 1 2 3 5 -1 3 4 1 2 4 5 1 -1 5 1 5 3 2 4 3 -1 5 6 1 5 1 2 1 1 2 3 1 2 3 4 1 -10 3 4 2 10 5 1 3 10 2 4 5 -10 10 10 23 47 5 8 43 13 9 5 55 43 4 9 84 -35 5 10 78 -70 6 4 15 70 7 3 15 67 1 7 2 58 6 7 86 20 5 7 77 7 2 9 32 -91 4 15 82 98 1 2 95 12 4 3 28 100 3 1 98 -25 2 3 39 12 1 2 21 5 1 4...
output:
2 -35 748 -24308 -5125 -4533 -10093 -13414 -13237 -8499 -6782 -6151 -15031 -13554 -50866 -2745 -14186 -5363 -13339 -23410 -5161 -12841 -7280 -22485 -15045 6008 -13410 -17388 -21254 -19576 -10606 -16471 -9741 -37226 -24158 -9383 -20665 -17547 -7919 -11201 -6651 -18673 -5076 -12809 -7285 -18708 -5878 ...
result:
ok 53406 lines