QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#403607 | #1067. TOLL | socpite | 0 | 0ms | 0kb | C++23 | 3.6kb | 2024-05-02 15:31:24 | 2024-11-07 12:41:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
const int INF = 1e9;
int n, m, k, cnt, rt;
int up1[maxn], up2[maxn];
int p_real[maxn], p[maxn], id[maxn], dp[maxn], dep[maxn], par[maxn], mark[maxn], mn[maxn];
bool in_tree[maxn];
long long ans = 0;
int Find(int x, int* up){
return up[x] < 0 ? x : up[x] = Find(up[x], up);
}
bool Union(int a, int b, int* up){
a = Find(a, up);
b = Find(b, up);
if(a == b)return false;
up[a] += up[b];
up[b] = a;
return true;
}
vector<pair<int, int>> g[maxn];
vector<pair<int, pair<int, int>>> E1, E2, important;
vector<pair<int, int>> fake;
void pre_dfs(int x){
dp[x] = p_real[x];
mn[x] = INF;
for(auto v: g[x]){
if(v.first == par[x])continue;
dep[v.first] = dep[x] + 1;
par[v.first] = x;
pre_dfs(v.first);
dp[x] += dp[v.first];
mark[v.first] = v.second;
}
}
void solve(int mask){
for(int i = 1; i <= cnt; i++){
up1[i] = -1;
g[i].clear();
}
for(int i = 0; i < k; i++){
if(!(mask&(1<<i)))continue;
if(!Union(fake[i].first, fake[i].second, up1))return;
g[fake[i].first].push_back({fake[i].second, 1});
g[fake[i].second].push_back({fake[i].first, 1});
}
for(int i = 0; i < important.size(); i++){
auto v = important[i];
in_tree[i] = Union(v.second.first, v.second.second, up1);
if(in_tree[i]){
g[v.second.first].push_back({v.second.second, 0});
g[v.second.second].push_back({v.second.first, 0});
}
}
pre_dfs(rt);
for(int i = 0; i < important.size(); i++){
if(in_tree[i])continue;
int w = important[i].first, a = important[i].second.first, b = important[i].second.second;
// cout << w << " " << a << " " << b << endl;
while(a != b){
if(dep[a] < dep[b])swap(a, b);
mn[a] = w;
a = par[a];
}
}
long long sum = 0;
for(int i = 1; i <= cnt; i++){
assert(mn[i] > 0 && dp[i] > 0);
if(mark[i])sum += mn[i]*dp[i];
}
assert(sum >= 0);
ans = max(ans, sum);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> k;
E1.resize(m);
for(auto &v: E1)cin >> v.second.first >> v.second.second >> v.first;
sort(E1.begin(), E1.end());
for(int i = 1; i <= n; i++)up1[i] = -1;
for(auto v: E1){
if(Union(v.second.first, v.second.second, up1))E2.push_back(v);
}
fake.resize(k);
for(auto &v: fake)cin >> v.first >> v.second;
for(int i = 1 ; i <= n; i++){
up1[i] = -1;
cin >> up2[i];
up2[i] *= -1;
}
for(auto v: fake)Union(v.first, v.second, up1);
for(auto v: E2){
if(Union(v.second.first, v.second.second, up1))Union(v.second.first, v.second.second, up2);
else important.push_back(v);
}
for(int i = 1; i <= n; i++){
if(up2[i] < 0){
cnt++;
id[i] = cnt;
p_real[cnt] = -up2[i];
assert(p_real[cnt] > 0);
}
}
rt = id[Find(1, up2)];
for(auto &v: fake){
v.first = id[Find(v.first, up2)];
v.second = id[Find(v.second, up2)];
// cout << v.first << " " << v.second << endl;
}
for(auto &v: important){
v.second.first = id[Find(v.second.first, up2)];
v.second.second = id[Find(v.second.second, up2)];
// cout << v.second.first << " " << v.second.second << endl;
}
for(int i = 1; i < (1<<k); i++)solve(i);
cout << ans;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
10 20 1 9 10 378587 3 10 283693 10 1 276961 8 1 828871 6 3 814717 3 5 701468 4 8 116841 7 5 859891 2 5 973550 9 2 460881 6 5 260184 8 9 895822 3 8 864166 10 4 746770 6 9 818592 7 1 748443 6 2 308698 6 7 170433 6 1 854347 2 10 641070 8 2 739814 240233 280283 628215 946109 596323 536584 590185 294679 ...
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%