結果

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

ソースコード

diff #
raw source code

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int T = 1; //cin >> T;
    while(T--){
        int N,M; cin >> N >> M;
        vector<pair<long long,int>> V(N);
        vector<tuple<int,int,int>> edge(M);
        for(auto &[a,b,c] : edge){
            cin >> a >> b >> c,a--,b--;
            V.at(a).first += c;
            V.at(b).first += c;
        }
        for(int i=0; i<N; i++) V.at(i).second = i;
        sort(V.rbegin(),V.rend());
        vector<int> C(N);
        for(int i=0; i<N; i++){
            auto [ign,pos] = V.at(i);
            C.at(pos) = i%2;
        }
        long long answer = 0;
        for(auto [a,b,c] : edge){
            if(C.at(a) == C.at(b)){
                if(C.at(a) == 0) answer += c;
                else answer -= c;
            }
        }
        cout << answer << "\n";
    }
}
0