結果

問題 No.3751 Nonopoly
コンテスト
ユーザー toppo57
提出日時 2026-10-31 14:51:56
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 43 ms / 2,000 ms
+ 945µs
コード長 528 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,504 ms
コンパイル使用メモリ 185,536 KB
実行使用メモリ 9,904 KB
最終ジャッジ日時 2026-10-31 14:52:40
合計ジャッジ時間 11,192 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge7_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M; cin>>N>>M;
    vector<ll> com(N+1, 0);
    for (int i=0;i<M;i++){
        int U, V; ll W; cin>>U>>V>>W;
        com[U]+=W;
        com[V]+=W;
    }
    sort(&com[1], &com[N+1], greater<ll>());

    ll a=0, b=0;
    for (int i=1;i<=N;i++){
        if (i%2==1) a+=com[i];
        else b+=com[i];
    }
    cout << (a-b)/2 << "\n";
    return 0;
}
0