Submission #1095013

# Submission time Handle Problem Language Result Execution time Memory
1095013 2024-10-01T07:19:12 Z hqminhuwu Training (IOI07_training) C++14
30 / 100
10 ms 12380 KB
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll,ll> pll;
typedef pair <int,int> pii;
typedef pair <int,pii> piii;

#define forr(_a,_b,_c) for(int _a = (_b); _a <= int (_c); ++_a)
#define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> int (_c);)
#define forf(_a,_b,_c) for(int _a = (_b); _a < int (_c); ++_a)
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"

template<class X, class Y>
    bool minz(X &x, const Y &y) {
        if (x > y) {
            x = y;
            return true;
        } return false;
    }
template<class X, class Y>
    bool maxz(X &x, const Y &y) {
        if (x < y) {
            x = y;
            return true;
        } return false;
    }

const int N = 5e5 + 5;
const ll oo = (ll) 1e16;
const ll mod = 1e9 + 7; // 998244353;

ll dp[N], dep[N], n, u, v, w, deg[N], m;
vector <pll> a[N];

void dfs (int u, int p){
    dp[u] = dp[p];
    dep[u] = dep[p] + 1;

    for (pll e : a[u]){
        ll v = e.st, w = e.nd;
        
        if (dep[v] && (dep[u] - dep[v]) & 1 && w){
            continue;
        }
        
        if (w && dep[v]){
            maxz(dp[u], dp[v] + w);
        }
    }   

    for (pll e : a[u])
    if (e.st != p && !e.nd)
        dfs(e.st, u);
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef hqm
        freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
    #endif

    cin >> n >> m;;

    ll sum = 0;

    forr (i, 1, m){
        cin >> u >> v >> w;
        
        a[u].pb(mp(v, w));
        a[v].pb(mp(u, w));

        sum += w;
    
        if (w == 0)
            deg[u]++, deg[v]++;
    }

    forr (i, 1, n)
    if (deg[i] == 1){
        dfs(i, 0);
        forr (j, i + 1, n)
        if (deg[j] == 1)
            cout << sum - dp[j] << "\n";
        return 0;
    }

    return 0;
}
/*



*/

# Verdict Execution time Memory Grader output
1 Correct 5 ms 12124 KB Output is correct
2 Correct 5 ms 12152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12124 KB Output is correct
2 Correct 6 ms 12240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12380 KB Output is correct
2 Correct 10 ms 12272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 12120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 12124 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 12120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 12376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 12348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 12376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 12376 KB Output isn't correct
2 Halted 0 ms 0 KB -