QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#698786 | #1067. TOLL | TheZone | 100 | 2ms | 11824kb | C++20 | 3.2kb | 2024-11-01 21:58:33 | 2024-11-01 21:58:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
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], dep[maxn], par[maxn], mark[maxn], mn[maxn];
long long dp[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;
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++){
if(mark[i])sum += 1LL*mn[i]*dp[i];
}assert(sum >= 0);
ans = max(ans, sum);}
signed 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)];
}
for(auto &v: important){
v.second.first = id[Find(v.second.first, up2)];
v.second.second = id[Find(v.second.second, up2)];
}
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: 100
Accepted
Test #1:
score: 100
Accepted
time: 0ms
memory: 11824kb
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:
909864568000
result:
ok single line: '909864568000'
Test #2:
score: 100
Accepted
time: 0ms
memory: 11796kb
input:
8 20 1 7 2 707898 6 4 739797 6 1 921019 7 3 739954 2 6 26438 5 4 242350 8 5 147225 7 6 53026 2 5 18161 5 1 319852 8 1 928770 6 5 291033 6 8 870601 3 5 596483 4 8 769617 1 4 516480 3 8 960359 2 3 672639 7 8 951165 3 4 911419 7 5 485318 528016 310567 880656 812984 803814 654959 289193
output:
34729855934
result:
ok single line: '34729855934'
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #3:
score: 0
Wrong Answer
time: 2ms
memory: 9860kb
input:
26 50 10 10 16 402572 16 17 883196 13 26 698082 5 16 96211 11 16 642512 16 22 44910 5 2 928962 3 24 834337 2 12 56104 18 1 851938 4 14 441768 6 21 793020 25 7 341805 7 22 664203 25 19 671175 8 7 362800 7 6 377915 21 20 975066 8 4 264657 4 26 445906 9 26 821755 18 9 285249 3 17 120207 11 15 816139 23...
output:
39221046380052
result:
wrong answer 1st lines differ - expected: '26876914464865', found: '39221046380052'
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%