QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#403608#1067. TOLLsocpite0 0ms7692kbC++233.6kb2024-05-02 15:31:582024-05-02 15:31:59

Judging History

你现在查看的是测评时间为 2024-05-02 15:31:59 的历史记录

  • [2024-11-07 12:41:10]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:1ms
  • 内存:7668kb
  • [2024-05-02 15:31:59]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:7692kb
  • [2024-05-02 15:31:58]
  • 提交

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;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 7692kb

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:

0

result:

wrong answer 1st lines differ - expected: '909864568000', found: '0'

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%