結果

問題 No.3751 Nonopoly
コンテスト
ユーザー marc2825
提出日時 2026-08-08 18:49:28
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 899 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,177 ms
コンパイル使用メモリ 222,384 KB
実行使用メモリ 9,928 KB
最終ジャッジ日時 2026-10-02 20:53:45
合計ジャッジ時間 4,924 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 18 WA * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

struct Edge {
    int u, v;
    long long w;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M;
    cin >> N >> M;

    vector<Edge> edges(M);
    vector<long long> mx(N);

    for (auto &[u, v, w] : edges) {
        cin >> u >> v >> w;
        u--, v--;

        mx[u] = max(mx[u], w);
        mx[v] = max(mx[v], w);
    }

    vector<int> ord(N);
    iota(ord.begin(), ord.end(), 0);

    sort(ord.begin(), ord.end(), [&](int a, int b) {
        if (mx[a] != mx[b]) return mx[a] > mx[b];
        return a < b;
    });

    vector<int> owner(N);
    for (int i = 0; i < N; ++i) {
        owner[ord[i]] = i % 2;
    }

    long long ans = 0;

    for (auto [u, v, w] : edges) {
        if (owner[u] != owner[v]) continue;

        if (owner[u] == 0) ans += w;
        else ans -= w;
    }

    cout << ans << '\n';
}
0