結果

問題 No.3751 Nonopoly
コンテスト
ユーザー marc2825
提出日時 2026-10-02 17:09:06
言語 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
結果
AC  
実行時間 42 ms / 2,000 ms
+ 156µs
コード長 685 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,113 ms
コンパイル使用メモリ 217,796 KB
実行使用メモリ 9,912 KB
最終ジャッジ日時 2026-10-02 21:07:00
合計ジャッジ時間 7,021 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

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

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

    vector<long long> degree(N, 0);

    for (int i = 0; i < M; ++i) {
        int u, v;
        long long w;
        cin >> u >> v >> w;

        --u;
        --v;

        degree[u] += w;
        degree[v] += w;
    }

    sort(degree.begin(), degree.end(), greater<long long>());

    long long twiceScore = 0;

    for (int i = 0; i < N; ++i) {
        if (i % 2 == 0) {
            twiceScore += degree[i];
        } else {
            twiceScore -= degree[i];
        }
    }

    cout << twiceScore / 2 << '\n';

    return 0;
}
0