답안 #794119

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
794119 2023-07-26T09:31:59 Z boyliguanhan Training (IOI07_training) C++17
10 / 100
7 ms 4436 KB
#include<bits/stdc++.h>
using namespace std;
vector<int> adj[1024];
struct npe {
    int a, b, c;
};
vector<npe>b[1024],edge;
int dep[1024], p[1024];
void dfs(int n) {
    for(auto i: adj[n])
        if(i!=p[n])
            p[i] = n, dep[i] = dep[n]+1, dfs(i);
}
int lca(int a, int b){
    while(dep[a]>dep[b]) a = p[a];
    while(dep[b]>dep[a]) b = p[b];
    while(a-b) a = p[a], b = p[b];
    return a;
}
int dp[1024][1024], bit[1024], ith[10];
void solve(int n) {
    int cnt = 0;
    for(auto i: adj[n])
        if(i!=p[n])
            solve(i);
    for(auto i: adj[n])
        if(i!=p[n])
            ith[cnt] = i, bit[i] = 1<<cnt++;
    for(int mask = 0; mask < 1<<cnt; mask++)
        for(int i = 0; i < cnt; i++)
            if(!(mask&1<<i))
                dp[n][mask]+=dp[ith[i]][0];
    for(auto x: b[n]) {
        int res = x.c, a = x.a, b = x.b;
        if(a!=n){
            res+=dp[a][0];
            for(;p[a]!=n;a=p[a])
                res+=dp[p[a]][bit[a]];
        }
        if(b!=n){
            res+=dp[b][0];
            for(;p[b]!=n;b=p[b])
                res+=dp[p[b]][bit[b]];
        }
        for(int mask = 0; mask < 1<<cnt; mask++)
            if(!(mask&(bit[x.a]|bit[x.b])))
                dp[n][mask] = max(dp[n][mask],dp[n][mask|bit[x.a]|bit[x.b]]+res);
    }
}
int main() {
    int n, m,sum=0;
    cin >> n >> m;
    while(m--) {
        int a, b, c;
        cin >> a >> b >> c;
        if(c)
            edge.push_back({a,b,c}), sum+=c;
        else
            adj[a].push_back(b),adj[b].push_back(a);
    }
    dfs(1);
    for(npe i: edge)
        if(1^(dep[i.a]+dep[i.b])%2)
        b[lca(i.a,i.b)].push_back(i);
    solve(1);
    cout << sum - dp[1][0] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 4436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 2036 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 1972 KB Output isn't correct
2 Halted 0 ms 0 KB -