Language: C++

4 2 3 6 1 5#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


struct topological_sort{
    const int V;
    vector<vector<int>> board;
    vector<int> into,list;
    vector<bool> visited;
    topological_sort(int v)
        :V(v)
        ,into(v,0)
        ,visited(v,false)
        {
            board.assign(v,vector<int>());
        }
    // 入力
    void add(int from,int to){
        board[from].push_back(to);
        into[to]++;
    }
    // トポロジカルソート
    void build(){
        for(int i=0;i<V;i++){
            if(into[i]==0&&!visited[i]){
                queue<int> q;
                q.push(i);
                while(q.size()){
                    int from=q.front(); q.pop();
                    list.push_back(from);
                    visited[from]=true;
                    for(int to:board[from]){
                        into[to]--;
                        if(into[to]==0&&!visited[to]){
                            q.push(to);
                        }
                    }
                }
            }
        }
    }
    // 取得
    vector<int> get(){
        return list;
    }
};
int main(){
    int V,E; cin>>V>>E; E+=V-1;
    topological_sort graph(V);
    vector<vector<int>> bboard(V);
    while(E--){
        int s,t; cin>>s>>t;
        graph.add(--s,--t);
        bboard[t].push_back(s);
    }
    graph.build();
    vector<int> l=graph.get();
    int used[V]={};
    int ans[V];
    rep(i,V){
        if(i==0){
            ans[l[i]]=-1;
            used[l[i]]=1;
        }else{
            int depth=0;
            for(int from:bboard[l[i]]){
                if(used[from]){
                    if(depth<used[from]){
                        depth=used[from];
                        ans[l[i]]=from;
                    }
                }
            }
            used[l[i]]=depth+1;
        }
    }
    rep(i,V){
        cout<<ans[i]+1<<endl;
    }
    return 0;
}


Compiler output:
a.cc:1:12: error: stray '#' in program
    1 | 4 2 3 6 1 5#include <bits/stdc++.h>
      |            ^
a.cc:1:1: error: expected unqualified-id before numeric constant
    1 | 4 2 3 6 1 5#include <bits/stdc++.h>
      | ^
a.cc:13:5: error: 'vector' does not name a type
   13 |     vector<vector<int>> board;
      |     ^~~~~~
a.cc:14:5: error: 'vector' does not name a type
   14 |     vector<int> into,list;
      |     ^~~~~~
a.cc:15:5: error: 'vector' does not name a type
   15 |     vector<bool> visited;
      |     ^~~~~~
a.cc:49:5: error: 'vector' does not name a type
   49 |     vector<int> get(){
      |     ^~~~~~
a.cc: In constructor 'topological_sort::topological_sort(int)':
a.cc:18:10: error: class 'topological_sort' does not have any field named 'into'
   18 |         ,into(v,0)
      |          ^~~~
a.cc:19:10: error: class 'topological_sort' does not have any field named 'visited'
   19 |         ,visited(v,false)
      |          ^~~~~~~
a.cc:21:13: error: 'board' was not declared in this scope
   21 |             board.assign(v,vector<int>());
      |             ^~~~~
a.cc:21:28: error: 'vector' was not declared in this scope
   21 |             board.assign(v,vector<int>());
      |                            ^~~~~~
a.cc:21:35: error: expected primary-expression before 'int'
   21 |             board.assign(v,vector<int>());
      |                                   ^~~
a.cc: In member function 'void topological_sort::add(int, int)':
a.cc:25:9: error: 'board' was not declared in this scope
   25 |         board[from].push_back(to);
      |         ^~~~~
a.cc:26:9: error: 'into' was not declared in this scope; did you mean 'int'?
   26 |         into[to]++;
      |         ^~~~
      |         int
a.cc: In member function 'void topological_sort::build()':
a.cc:31:16: error: 'into' was not declared in this scope; did you mean 'int'?
   31 |             if(into[i]==0&&!visited[i]){
      |                ^~~~
      |                int
a.cc:31:29: error: 'visited' was not declared in this scope
   31 |             if(into[i]==0&&!visited[i]){
      |                             ^~~~~~~
a.cc:32:17: error: 'queue' was not declared in this scope
   32 |                 queue<int> q;
      |                 ^~~~~
a.cc:32:23: error: expected primary-expression before 'int'
   32 |                 queue<int> q;
      |                       ^~~
a.cc:33:17: error: 'q' was not declared in this scope
   33 |                 q.push(i);
      |                 ^
a.cc:36:21: error: 'list' was not declared in this scope
   36 |                     list.push_back(from);
      |                     ^~~~
a.cc:38:32: error: 'board' was not declared in this scope
   38 |                     for(int to:board[from]){
      |                                ^~~~~
a.cc: In function 'int main()':
a.cc:54:14: error: 'cin' was not declared in this scope
   54 |     int V,E; cin>>V>>E; E+=V-1;
      |              ^~~
a.cc:56:5: error: 'vector' was not declared in this scope
   56 |     vector<vector<int>> bboard(V);
      |     ^~~~~~
a.cc:56:19: error: expected primary-expression before 'int'
   56 |     vector<vector<int>> bboard(V);
      |                   ^~~
a.cc:60:9: error: 'bboard' was not declared in this scope
   60 |         bboard[t].push_back(s);
      |         ^~~~~~
a.cc:63:12: error: expected primary-expression before 'int'
   63 |     vector<int> l=graph.get();
      |            ^~~
a.cc:68:17: error: 'l' was not declared in this scope
   68 |             ans[l[i]]=-1;
      |                 ^
a.cc:72:26: error: 'bboard' was not declared in this scope
   72 |             for(int from:bboard[l[i]]){
      |                          ^~~~~~
a.cc:72:33: error: 'l' was not declared in this scope
   72 |             for(int from:bboard[l[i]]){
      |                                 ^
a.cc:80:18: error: 'l' was not declared in this scope
   80 |             used[l[i]]=depth+1;
      |                  ^
a.cc:84:9: error: 'cout' was not declared in this scope
   84 |         cout<<ans[i]+1<<endl;
      |         ^~~~
a.cc:84:25: error: 'endl' was not declared in this scope
   84 |         cout<<ans[i]+1<<endl;
      |                         ^~~~