Language: C++

import std.stdio;
import std.conv;
import std.array;
import std.algorithm;

const bool DEBUG = true;

class Node {
    string name;
    Node[] parents;
    Node[] children;

    static Node birth, end;

    static this() {
        birth = new Node;
        end = new Node;
    }

    private this() {}

    this(string name) {
        this.name = name;
        birth.children ~= this;
        parents = [birth];
        end.parents ~= this;
        children = [end];
    }

    private int _fromBirth = -1;
    @property int fromBirth() {
        if (_fromBirth >= 0) return _fromBirth;
        int dist = 0;
        foreach (p; parents) {
            dist = max(dist, p.fromBirth + 1);
        }
        return _fromBirth = dist;
    }

    private int _toEnd = -1;
    @property int toEnd() {
        if (_toEnd >= 0) return _toEnd;
        int dist = 0;
        foreach (c; children) {
            dist = max(dist, c.toEnd + 1);
        }
        return _toEnd = dist;
    }

    static int longest() {
        return birth.toEnd;
    }
}

void main() {
    int n, m; readf("%d %d\n", &n, &m);
    Node[] employees = new Node[n + 1];
    foreach (i; 1 .. n + 1) {
        employees[i] = new Node(i.to!string);
    }

    int[] as = new int[m];
    int[] bs = new int[m];
    foreach (i; 0 .. m) {
        int a, b; readf("%d %d\n", &a, &b);
        as[i] = a; bs[i]  = b;
        employees[a].children ~= employees[b];
        employees[b].parents  ~= employees[a];
    }

    int[] list;
    int[] fromFlag = new int[n + 1];
    int[] toFlag   = new int[n + 1];
    foreach (i; 0 .. m) {
        auto a = employees[as[i]];
        auto b = employees[bs[i]];
        if (a.fromBirth + b.toEnd + 1 == Node.longest) {
            fromFlag[as[i]]++;
            toFlag[bs[i]]++;
            list ~= i;
        }
    }

    int[] ans;
    foreach (i; list) {
        if (fromFlag[as[i]] > 1 || toFlag[bs[i]] > 1) continue;
        ans ~= i + 1;
    }

    (ans.length ? ans.map!(to!string).join("\n") : "-1").writeln;
}

Compiler output:
a.cc:31:5: error: stray '@' in program
   31 |     @property int fromBirth() {
      |     ^
a.cc:41:5: error: stray '@' in program
   41 |     @property int toEnd() {
      |     ^
a.cc:1:1: error: 'import' does not name a type
    1 | import std.stdio;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import std.conv;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import std.array;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import std.algorithm;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:9:5: error: 'string' does not name a type
    9 |     string name;
      |     ^~~~~~
a.cc:10:9: error: expected unqualified-id before '[' token
   10 |     Node[] parents;
      |         ^
a.cc:11:9: error: expected unqualified-id before '[' token
   11 |     Node[] children;
      |         ^
a.cc:15:12: error: expected unqualified-id before 'this'
   15 |     static this() {
      |            ^~~~
a.cc:20:12: error: expected ':' before 'this'
   20 |     private this() {}
      |            ^~~~~
      |            :
a.cc:20:13: error: expected unqualified-id before 'this'
   20 |     private this() {}
      |             ^~~~
a.cc:22:5: error: expected unqualified-id before 'this'
   22 |     this(string name) {
      |     ^~~~
a.cc:30:12: error: expected ':' before 'int'
   30 |     private int _fromBirth = -1;
      |            ^~~~
      |            :
a.cc:31:6: error: 'property' does not name a type
   31 |     @property int fromBirth() {
      |      ^~~~~~~~
a.cc:40:12: error: expected ':' before 'int'
   40 |     private int _toEnd = -1;
      |            ^~~~
      |            :
a.cc:41:6: error: 'property' does not name a type
   41 |     @property int toEnd() {
      |      ^~~~~~~~
a.cc:53:2: error: expected ';' after class definition
   53 | }
      |  ^
      |  ;
a.cc: In static member function 'static int Node::longest()':
a.cc:51:22: error: 'class Node' has no member named 'toEnd'; did you mean '_toEnd'?
   51 |         return birth.toEnd;
      |                      ^~~~~
      |                      _toEnd
a.cc: At global scope:
a.cc:55:1: error: '::main' must return 'int'
   55 | void main() {
      | ^~~~
a.cc: In function 'int main()':
a.cc:56:15: error: 'readf' was not declared in this scope
   56 |     int n, m; readf("%d %d\n", &n, &m);
      |               ^~~~~
a.cc:57:9: error: structured binding declaration cannot have type 'Node'
   57 |     Node[] employees = new Node[n + 1];
      |         ^~
a.cc:57:9: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:57:9: error: empty structured binding declaration
a.cc:57:12: error: expected initializer before 'employees'
   57 |     Node[] employees = new Node[n + 1];
      |            ^~~~~~~~~
a.cc:58:14: error: 'i' was not declared in this scope
   58 |     foreach (i; 1 .. n + 1) {
      |              ^
a.cc:58:20: error: expected unqualified-id before '.' token
   58 |     foreach (i; 1 .. n + 1) {
      |                    ^
a.cc:62:8: error: structured binding declaration cannot have type 'int'
   62 |     int[] as = new int[m];
      |        ^~
a.cc:62:8: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:62:8: error: empty structured binding declaration
a.cc:62:11: error: expected initializer before 'as'
   62 |     int[] as = new int[m];
      |           ^~
a.cc:63:8: error: structured binding declaration cannot have type 'int'
   63 |     int[] bs = new int[m];
      |        ^~
a.cc:63:8: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:63:8: error: empty structured binding declaration
a.cc:63:11: error: expected initializer before 'bs'
   63 |     int[] bs = new int[m];
      |           ^~
a.cc:64:15: error: expected ')' before ';' token
   64 |     foreach (i; 0 .. m) {
      |             ~ ^
      |               )
a.cc:64:20: error: expected unqualified-id before '.' token
   64 |     foreach (i; 0 .. m) {
      |                    ^
a.cc:71:8: error: structured binding declaration cannot have type 'int'
   71 |     int[] list;
      |        ^~
a.cc:71:8: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:71:8: error: empty structured binding declaration
a.cc:71:11: error: expected initializer before 'list'
   71 |     int[] list;
      |           ^~~~
a.cc:72:8: error: structured binding declaration cannot have type 'int'
   72 |     int[] fromFlag = new int[n + 1];
      |        ^~
a.cc:72:8: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:72:8: error: empty structured binding declaration
a.cc:72:11: error: expected initializer before 'fromFlag'
   72 |     int[] fromFlag = new int[n + 1];
      |           ^~~~~~~~
a.cc:73:8: error: structured binding declaration cannot have type 'int'
   73 |     int[] toFlag   = new int[n + 1];
      |        ^~
a.cc:73:8: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:73:8: error: empty structured binding declaration
a.cc:73:11: error: expected initializer before 'toFlag'
   73 |     int[] toFlag   = new int[n + 1];
      |           ^~~~~~
a.cc:74:15: error: expected ')' before ';' token
   74 |     foreach (i; 0 .. m) {
      |             ~ ^
      |               )
a.cc:74:20: error: expected unqualified-id before '.' token
   74 |     foreach (i; 0 .. m) {
      |                    ^
a.cc:84:8: error: structured binding declaration cannot have type 'int'
   84 |     int[] ans;
      |        ^~
a.cc:84:8: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:84:8: error: empty structured binding declaration
a.cc:84:11: error: expected initializer before 'ans'
   84 |     int[] ans;
      |           ^~~
a.cc:85:15: error: expected ')' before ';' token
   85 |     foreach (i; list) {
      |             ~ ^
      |               )
a.cc:85:17: error: 'list' was not declared in this scope
   85 |     foreach (i; list) {
      |                 ^~~~
a.cc:90:6: error: 'ans' was not declared in this scope
   90 |     (ans.length ? ans.map!(to!string).join("\n") : "-1").writeln;
      |      ^~~
a.cc:90:26: error: expected ':' before '!' token
   90 |     (ans.length ? ans.map!(to!string).join("\n") : "-1").writeln;
      |                          ^
      |                          :
a.cc:90:28: error: 'to' was not declared in this scope
   90 |     (ans.length ? ans.map!(to!string).join("\n") : "-1").writeln;
      |                            ^~
a.cc:90:30: error: expected ')' before '!' token
   90 |     (ans.length ? ans.map!(to!string).join("\n") : "-1").writeln;
      |                           ~  ^
      |                              )
a.cc:90:65: error: expected ')' before ';' token
   90 |     (ans.length ? ans.map!(to!string).join("\n") : "-1").writeln;
      |     ~                                                           ^
      |                                                                 )