Language: C++

/+ dub.sdl:
    name "A"
    dependency "dcomp" version=">=0.4.0"
+/

import std.stdio, std.algorithm, std.conv, std.range;
import std.typecons, std.math;

// import dcomp.scanner, dcomp.graph.namori;

alias E = Tuple!(int, "to");

long solve(E[][] g) {
    int n = g.length.to!int;
    if (n % 2) return 10L^^18;
    int[] sz = new int[n];
    int[] csm = new int[n];
    long ans = 0;
    void dfs(int p, int b, bool c) {
        sz[p] = 1;
        if (c) csm[p] = 1;
        foreach (e; g[p]) {
            int d = e.to;
            if (d == b) continue;
            dfs(d, p, !c);
            sz[p] += sz[d];
            csm[p] += csm[d];
        }
        ans += abs(sz[p] - 2*csm[p]);
    }
    dfs(0, -1, 0);
    return ans;
}


int main() {
    auto sc = new Scanner(stdin);
    int n, m;
    sc.read(n, m);
    E[][] g = new E[][n];
    foreach (i; 0..m) {
        int a, b;
        sc.read(a, b); a--; b--;
        g[a] ~= E(b);
        g[b] ~= E(a);
    }
    if (n % 2) {
        writeln(0);
        return 0;
    }
    if (m == n-1) {
        //not namori
        writeln(solve(g));
    }

    return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/graph/namori.d */
// module dcomp.graph.namori;

// import dcomp.graph.dfsinfo;

struct Namori {
    bool[] isCycle;
    int[][] cycles;
    int[] root;
    this(int n) {
        isCycle = new bool[n];
        root = new int[n];
    }
}

Namori namori(T)(T g) {
    import std.algorithm : find, each;
    import std.range;
    import std.conv : to;
    int n = g.length.to!int;
    auto info = dfsInfo(g);
    auto nmr = Namori(n);
    with (nmr) {
        //find self loop
        foreach (i; 0..n) {
            if (g[i].find!(e => e.to == i).empty) continue;
            isCycle[i] = true;
            cycles ~= [i];
        }
        foreach (p; info.vlis) {
            if (info.low[p] == info.ord[p]) continue;
            if (g[p].length == info.tr[p].length+1) continue;
            int[] v;
            int nw = p;
            while (info.ord[nw] != info.low[p]) {
                v ~= nw;
                nw = info.par[nw];
            }
            v ~= nw;
            v.each!(i => isCycle[i] = true);
            cycles ~= v;
        }
        bool[] used = new bool[n];
        void dfs(int p, int b, int r) {
            if (used[p]) return;
            used[p] = true;
            root[p] = r;
            foreach (e; g[p]) {
                int d = e.to;
                if (d == b) continue;
                if (isCycle[d]) continue;
                dfs(d, p, r);
            }
        }
        foreach (i; 0..n) {
            if (!isCycle[i]) continue;
            dfs(i, -1, i);
        }
    }
    return nmr;
}

Namori directedNamori(int[] g) {
    import std.algorithm : find, each;
    import std.range;
    import std.conv : to;
    int n = g.length.to!int;
    auto nmr = Namori(n);
    with (nmr) {
        int[] used = new int[n]; used[] = -1;
        foreach (i; 0..n) {
            if (used[i] != -1) continue;
            int j = i;
            while (used[j] == -1) {
                used[j] = i;
                j = g[j];
            }
            if (used[j] != i) continue;
            int k = j;
            int[] cy = [];
            while (true) {
                cy ~= k;
                isCycle[k] = true;
                if (g[k] == j) break;
                k = g[k];
            }
            cycles ~= cy;
        }
        int[] dp = new int[n]; dp[] = -1;
        int dfs(int p) {
            if (isCycle[p]) return p;
            if (dp[p] != -1) return dp[p];
            return dp[p] = dfs(g[p]);
        }
        foreach (i; 0..n) {
            root[i] = dfs(i);
        }
    }
    return nmr;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray; 
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    string[] buf;
    private bool succ() {
        while (!buf.length) {
            if (f.eof) return false;
            buf = f.readln.split;
        }
        return true;
    }
    private bool readSingle(T)(ref T x) {
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {
                //string or char[10] etc
                x = buf.front;
                buf.popFront;
            } else {
                static if (isStaticArray!T) {
                    //static
                    assert(buf.length == T.length);
                }
                x = buf.map!(to!E).array;
                buf.length = 0;                
            }
        } else {
            x = buf.front.to!T;
            buf.popFront;            
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}

unittest {
    import std.path : buildPath;
    import std.file : tempDir;
    import std.algorithm : equal;
    import std.stdio : File;
    string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
    auto fout = File(fileName, "w");
    fout.writeln("1 2 3");
    fout.writeln("ab cde");
    fout.writeln("1.0 1.0 2.0");
    fout.close;
    Scanner sc = new Scanner(File(fileName, "r"));
    int a;
    int[2] b;
    char[2] c;
    string d;
    double e;
    double[] f;
    sc.read(a, b, c, d, e, f);
    assert(a == 1);
    assert(equal(b[], [2, 3]));
    assert(equal(c[], "ab"));
    assert(equal(d, "cde"));
    assert(e == 1.0);
    assert(equal(f, [1.0, 2.0]));
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/graph/dfsinfo.d */
// module dcomp.graph.dfsinfo;

struct DFSInfo {
    int[] low, ord, par, vlis; //low, ord, parent, visitList
    int[][] tr; //dfs tree(directed)
    this(int n) {
        low = new int[n];
        ord = new int[n];
        par = new int[n];
        vlis = new int[n];
        tr = new int[][](n);
    }
}

DFSInfo dfsInfo(T)(T g) {
    import std.algorithm : min, each, filter;
    import std.conv : to;
    const int n = g.length.to!int;
    auto info = DFSInfo(n);
    with(info) {
        int co = 0;
        bool[] used = new bool[](n);
        void dfs(int p, int b) {
            used[p] = true;
            low[p] = ord[p] = co++;
            par[p] = b;

            bool rt = true;
            foreach (e; g[p]) {
                int d = e.to;
                if (rt && d == b) {
                    rt = false;
                    continue;
                }
                if (!used[d]) {
                    dfs(d, p);
                    low[p] = min(low[p], low[d]);
                } else {
                    low[p] = min(low[p], ord[d]);
                }
            }
        }
            
        foreach (i; 0..n) {
            if (used[i]) continue;
            dfs(i, -1);
        }
        par.filter!"a!=-1".each!((i, v) => tr[v] ~= i.to!int);
        ord.each!((i, v) => vlis[v] = i.to!int);
    }
    return info;
}


Compiler output:
a.cc:41:17: error: too many decimal points in number
   41 |     foreach (i; 0..m) {
      |                 ^~~~
a.cc:82:21: error: too many decimal points in number
   82 |         foreach (i; 0..n) {
      |                     ^~~~
a.cc:112:21: error: too many decimal points in number
  112 |         foreach (i; 0..n) {
      |                     ^~~~
a.cc:128:21: error: too many decimal points in number
  128 |         foreach (i; 0..n) {
      |                     ^~~~
a.cc:152:21: error: too many decimal points in number
  152 |         foreach (i; 0..n) {
      |                     ^~~~
a.cc:282:21: error: too many decimal points in number
  282 |         foreach (i; 0..n) {
      |                     ^~~~
a.cc:1:1: error: expected unqualified-id before '/' token
    1 | /+ dub.sdl:
      | ^
a.cc:7:1: error: 'import' does not name a type
    7 | import std.typecons, std.math;
      | ^~~~~~
a.cc:7:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:11:1: error: 'alias' does not name a type
   11 | alias E = Tuple!(int, "to");
      | ^~~~~
a.cc:13:12: error: 'E' was not declared in this scope
   13 | long solve(E[][] g) {
      |            ^
a.cc:13:14: error: expected primary-expression before ']' token
   13 | long solve(E[][] g) {
      |              ^
a.cc:13:16: error: expected primary-expression before ']' token
   13 | long solve(E[][] g) {
      |                ^
a.cc: In function 'int main()':
a.cc:37:19: error: expected type-specifier before 'Scanner'
   37 |     auto sc = new Scanner(stdin);
      |                   ^~~~~~~
a.cc:40:5: error: 'E' was not declared in this scope
   40 |     E[][] g = new E[][n];
      |     ^
a.cc:40:7: error: expected primary-expression before ']' token
   40 |     E[][] g = new E[][n];
      |       ^
a.cc:40:9: error: expected primary-expression before ']' token
   40 |     E[][] g = new E[][n];
      |         ^
a.cc:41:14: error: 'i' was not declared in this scope
   41 |     foreach (i; 0..m) {
      |              ^
a.cc:48:9: error: 'writeln' was not declared in this scope
   48 |         writeln(0);
      |         ^~~~~~~
a.cc:53:23: error: 'g' was not declared in this scope
   53 |         writeln(solve(g));
      |                       ^
a.cc:53:24: error: 'solve' cannot be used as a function
   53 |         writeln(solve(g));
      |                        ^
a.cc:53:9: error: 'writeln' was not declared in this scope
   53 |         writeln(solve(g));
      |         ^~~~~~~
a.cc: At global scope:
a.cc:64:9: error: expected unqualified-id before '[' token
   64 |     bool[] isCycle;
      |         ^
a.cc:65:8: error: expected unqualified-id before '[' token
   65 |     int[][] cycles;
      |        ^
a.cc:66:8: error: expected unqualified-id before '[' token
   66 |     int[] root;
      |        ^
a.cc:67:5: error: expected unqualified-id before 'this'
   67 |     this(int n) {
      |     ^~~~
a.cc:73:8: error: expected initializer before 'namori'
   73 | Namori namori(T)(T g) {
      |        ^~~~~~
a.cc:120:29: error: expected ',' or '...' before 'g'
  120 | Namori directedNamori(int[] g) {
      |                             ^
a.cc: In function 'Namori directedNamori(int*)':
a.cc:121:5: error: 'import' was not declared in this scope
  121 |     import std.algorithm : find, each;
      |     ^~~~~~
a.cc:122:11: error: expected ';' before 'std'
  122 |     import std.range;
      |           ^~~~
      |           ;
a.cc:123:11: error: expected ';' before 'std'
  123 |     import std.conv : to;
      |           ^~~~
      |           ;
a.cc:124:13: error: 'g' was not declared in this scope
  124 |     int n = g.length.to!int;
      |             ^
a.cc:125:24: error: no matching function for call to 'Namori::Namori(int&)'
  125 |     auto nmr = Namori(n);
      |                        ^
a.cc:63:8: note: candidate: 'constexpr Namori::Namori()'
   63 | struct Namori {
      |        ^~~~~~
a.cc:63:8: note:   candidate expects 0 arguments, 1 provided
a.cc:63:8: note: candidate: 'constexpr Namori::Namori(const Namori&)'
a.cc:63:8: note:   no known conversion for argument 1 from 'int' to 'const Namori&'
a.cc:63:8: note: candidate: 'constexpr Namori::Namori(Namori&&)'
a.cc:63:8: note:   no known conversion for argument 1 from 'int' to 'Namori&&'
a.cc:126:5: error: 'with' was not declared in this scope
  126 |     with (nmr) {
      |     ^~~~
a.cc: At global scope:
a.cc:162:5: error: 'import' does not name a type
  162 |     import std.stdio : File;
      |     ^~~~~~
a.cc:162:5: note: C++20 'import' only available with '-fmodules-ts'
a.cc:163:5: error: 'import' does not name a type
  163 |     import std.conv : to;
      |     ^~~~~~
a.cc:163:5: note: C++20 'import' only available with '-fmodules-ts'
a.cc:164:5: error: 'import' does not name a type
  164 |     import std.range : front, popFront, array, ElementType;
      |     ^~~~~~
a.cc:164:5: note: C++20 'import' only available with '-fmodules-ts'
a.cc:165:5: error: 'import' does not name a type
  165 |     import std.array : split;
      |     ^~~~~~
a.cc:165:5: note: C++20 'import' only available with '-fmodules-ts'
a.cc:166:5: error: 'import' does not name a type
  166 |     import std.traits : isSomeChar, isStaticArray, isArray;
      |     ^~~~~~
a.cc:166:5: note: C++20 'import' only available with '-fmodules-ts'
a.cc:167:5: error: 'import' does not name a type
  167 |     import std.algorithm : map;
      |     ^~~~~~
a.cc:167:5: note: C++20 'import' only available with '-fmodules-ts'
a.cc:168:5: error: 'File' does not name a type
  168 |     File f;
      |     ^~~~
a.cc:169:5: error: expected unqualified-id before 'this'
  169 |     this(File f) {
      |     ^~~~
a.cc:172:5: error: 'string' does not name a type
  172 |     string[] buf;
      |     ^~~~~~
a.cc:173:12: error: expected ':' before 'bool'
  173 |     private bool succ() {
      |            ^~~~~
      |            :
a.cc:180:12: error: expected ':' before 'bool'
  180 |     private bool readSingle(T)(ref T x) {
      |            ^~~~~
      |            :
a.cc:180:29: error: 'T' has not been declared
  180 |     private bool readSingle(T)(ref T x) {
      |                             ^
a.cc:180:32: error: 'ref' has not been declared
  180 |     private bool readSingle(T)(ref T x) {
      |                                ^~~
a.cc:180:38: error: expected ',' or '...' before 'x'
  180 |     private bool readSingle(T)(ref T x) {
      |                                      ^
a.cc:180:13: error: 'readSingle' declared as function returning a function
  180 |     private bool readSingle(T)(ref T x) {
      |             ^~~~
a.cc:202:14: error: 'T' has not been declared
  202 |     int read(T, Args...)(ref T x, auto ref Args args) {
      |              ^
a.cc:202:17: error: 'Args' has not been declared
  202 |     int read(T, Args...)(ref T x, auto ref Args args) {
      |                 ^~~~
a.cc:202:26: error: 'ref' has not been declared
  202 |     int read(T, Args...)(ref T x, auto ref Args args) {
      |                          ^~~
a.cc:202:32: error: expected ',' or '...' before 'x'
  202 |     int read(T, Args...)(ref T x, auto ref Args args) {
      |                                ^
a.cc:202:5: error: 'read' declared as function returning a function
  202 |     int read(T, Args...)(ref T x, auto ref Args args) {
      |     ^~~
a.cc: In member function 'bool Scanner::succ()':
a.cc:174:17: error: 'buf' was not declared in this scope
  174 |         while (!buf.length) {
      |                 ^~~
a.cc:175:17: error: 'f' was not declared in this scope
  175 |             if (f.eof) return false;
      |                 ^
a.cc:176:19: error: 'f' was not declared in this scope
  176 |             buf = f.readln.split;
      |                   ^
a.cc: At global scope:
a.cc:213:5: error: 'import' was not declared in this scope
  213 |     import std.path : buildPath;
      |     ^~~~~~
a.cc:213:12: error: expected '}' before 'std'
  213 |     import std.path : buildPath;
      |            ^~~
a.cc:212:10: note: to match this '{'
  212 | unittest {
      |          ^
a.cc:213:12: error: expected ',' or ';' before 'std'
  213 |     import std.path : buildPath;
      |            ^~~
a.cc:214:5: error: 'import' does not name a type
  214 |     import std.file : tempDir;
      |     ^~~~~~
a.cc:214:5: note: C++20 'import' only available with '-fmodules-ts'
a.cc:215:5: error: 'import' does not name a type
  215 |     import std.algorithm : equal;
      |     ^~~~~~
a.cc:215:5: note: C++20 'import' only available with '-fmodules-ts'
a.cc:216:5: error: 'import' does not name a type
  216 |     import std.stdio : File;
      |     ^~~~~~
a.cc:216:5: note: C++20 'import' only available with '-fmodules-ts'
a.cc:217:5: error: 'string' does not name a type
  217 |     string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
      |     ^~~~~~
a.cc:218:22: error: 'fileName' was not declared in this scope
  218 |     auto fout = File(fileName, "w");
      |                      ^~~~~~~~
a.cc:218:17: error: 'File' was not declared in this scope
  218 |     auto fout = File(fileName, "w");
      |                 ^~~~
a.cc:219:5: error: 'fout' does not name a type
  219 |     fout.writeln("1 2 3");
      |     ^~~~
a.cc:220:5: error: 'fout' does not name a type
  220 |     fout.writeln("ab cde");
      |     ^~~~
a.cc:221:5: error: 'fout' does not name a type
  221 |     fout.writeln("1.0 1.0 2.0");
      |     ^~~~
a.cc:222:5: error: 'fout' does not name a type
  222 |     fout.close;
      |     ^~~~
a.cc:223:35: error: 'fileName' was not declared in this scope
  223 |     Scanner sc = new Scanner(File(fileName, "r"));
      |                                   ^~~~~~~~
a.cc:223:30: error: 'File' was not declared in this scope
  223 |     Scanner sc = new Scanner(File(fileName, "r"));
      |                              ^~~~
a.cc:225:9: error: expected identifier before numeric constant
  225 |     int[2] b;
      |         ^
a.cc:225:9: error: expected ']' before numeric constant
  225 |     int[2] b;
      |         ^
      |         ]
a.cc:225:8: error: structured binding declaration cannot have type 'int'
  225 |     int[2] b;
      |