結果

問題 No.3751 Nonopoly
コンテスト
ユーザー InTheBloom
提出日時 2026-10-02 22:09:37
言語 D
(dmd 2.113.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
AC  
実行時間 128 ms / 2,000 ms
+ 136µs
コード長 1,096 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,161 ms
コンパイル使用メモリ 170,676 KB
実行使用メモリ 9,872 KB
最終ジャッジ日時 2026-10-02 22:09:59
合計ジャッジ時間 10,756 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import std;

void main () {
    int N, M;
    readln.read(N, M);
    auto u = new int[](M);
    auto v = new int[](M);
    auto W = new int[](M);
    foreach (i; 0 .. M) {
        readln.read(u[i], v[i], W[i]);
        u[i]--, v[i]--;
    }

    // ??

    auto pts = new long[](N);
    foreach (i; 0 .. M) {
        pts[u[i]] += W[i];
        pts[v[i]] += W[i];
    }

    auto ord = iota(N).array;
    ord.sort!((a, b) => pts[b] < pts[a]);

    auto al = new bool[](N);
    auto bo = new bool[](N);
    foreach (index, i; ord.enumerate(0)) {
        if (index % 2 == 0) {
            al[i] = true;
        }
        else {
            bo[i] = true;
        }
    }

    long score = 0;
    foreach (i; 0 .. M) {
        if (al[u[i]] && al[v[i]]) {
            score += W[i];
        }
        if (bo[u[i]] && bo[v[i]]) {
            score -= W[i];
        }
    }

    writeln(score);
}

void read (T...) (string S, ref T args) {
    import std.conv : to;
    import std.array : split;
    auto buf = S.split;
    foreach (i, ref arg; args) {
        arg = buf[i].to!(typeof(arg));
    }
}
0