Submission #1822785


Source Code Expand

Copy
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto edges = new int[][](N, N);
    foreach (_; 0..M) {
        s = readln.split.map!(to!int);
        edges[s[0]-1][s[1]-1] = 1;
        edges[s[1]-1][s[0]-1] = 1;
    }

    int cnt(int n) {
        int ret = 0;
        foreach (i; 0..N)
            if (edges[n][i]) {
                ret -= 1;
                foreach (j; 0..N)
                    ret += edges[i][j];
            }
        return ret;
    }

    int ans = 0;
    auto used = new bool[](N);

    foreach (i; 0..N) {
        auto q = N.iota.filter!(i => !used[i]).array;
        if (q.empty)
            break;
        q.sort!((a, b) => edges[a].sum == edges[b] ? cnt(a) > cnt(b) : edges[a].sum < edges[b].sum);
        int n = q[0];
        ans += 1;
        used[n] = true;
        foreach (j; 0..N) {
            if (edges[n][j]) {
                foreach (k; 0..N) edges[j][k] = 0, edges[k][j] = 0;
                used[j] = true;
            }
        }
    }

    ans.writeln;
}

Submission Info

Submission Time
Task G - Mixture Drug
User nebukuro09
Language D (LDC 0.17.0)
Score 0
Code Size 1276 Byte
Status CE

Compile Error

./Main.d(34): Error: incompatible types for ((sum(edges[cast(ulong)a])) == (edges[cast(ulong)b])): 'int' and 'int[]'
./Main.d(34):        instantiated from here: sort!((a, b) => edges[a].sum == edges[b] ? cnt(a) > cnt(b) : edges[a].sum < edges[b].sum, cast(SwapStrategy)0, int[])
/opt/ldc/bin/../import/std/algorithm/sorting.d(980): Error: static assert  "Invalid predicate passed to sort: __lambda3"
./Main.d(34):        instantiated from here: sort!((a, b) => edges[a].sum == edges[b] ? cnt(a) > cnt(b) : edges[a].sum < edges[b].sum, cast(SwapStrategy)0, int[])