Language: Java

#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
using namespace std;
typedef long long llong;

struct edge{
	int k,next,ans,id;
};
const int SN = 502000;
edge e1[SN*2],e2[SN*2];
int f1[SN],f[SN],f2[SN];
bool bi[SN];
int n,root,p1,p2,nn,mm;

int s(int k){
	if (f[k]) return (f[k]=s(f[k]));
	else return k;
}

void addedge(int p,int q){
	e1[++nn].k=q;
	e1[nn].next=f1[p];
	f1[p]=nn;
}

void addedge1(int p,int q,int id){
	e2[++mm].k=q;
	e2[mm].next=f2[p];
	e2[mm].id=id;
	e2[mm].ans=0;
	f2[p]=mm;
}

void tarjan(int k){
	for (int i=f1[k];i;i=e1[i].next){
		tarjan(e1[i].k);
		f[s(e1[i].k)]=k;
	}
	bi[k]=true;
	for (int i=f2[k];i;i=e2[i].next)
	 if (bi[e2[i].k]) e2[i].ans=s(e2[i].k);
}

struct Node
{
    int tree,root;
    bool incir;
    int cirid,dep;
    int fa;
}P[500010];
int Mark[500010],Cnt;
bool Vis[500010];
int DFS(int Now)
{
    Mark[Now]=Cnt;
    Vis[Now]=true;
    if (Vis[P[Now].fa])
    {
        if (Mark[P[Now].fa]==Cnt)
        {
            P[Now].tree=Cnt;
            P[Now].incir=true;
            P[Now].cirid=1;
            P[Now].root=Now;
            P[Now].dep=1;
            return P[Now].fa;
        }
        else
        {
            P[Now].tree=P[P[Now].fa].tree;
            P[Now].root=P[P[Now].fa].root;
            P[Now].dep=P[P[Now].fa].dep+1;
            return -1;
        }
    }
    else
    {
        int tmp=DFS(P[Now].fa);
        if (tmp<0)
        {
            P[Now].tree=P[P[Now].fa].tree;
            P[Now].root=P[P[Now].fa].root;
            P[Now].dep=P[P[Now].fa].dep+1;
            return -1;
        }
        else if (tmp==Now)
        {
            P[Now].tree=P[P[Now].fa].tree;
            P[Now].root=Now;
            P[Now].incir=true;
            P[Now].cirid=P[P[Now].fa].cirid+1;
            P[Now].dep=1;
            return -1;
        }
        else
        {
            P[Now].tree=P[P[Now].fa].tree;
            P[Now].incir=true;
            P[Now].root=Now;
            P[Now].dep=1;
            P[Now].cirid=P[P[Now].fa].cirid+1;
            return tmp;
        }
    }
}
int main()
{
    int N,Q,i;
    while (~scanf("%d%d",&N,&Q))
    {
        for (i=1;i<=N;i++)
        {
            scanf("%d",&P[i].fa);
            Vis[i]=false;
            P[i].incir=false;
            Mark[i]=-1;
        }
        Cnt=1;
        for (i=1;i<=N;++i) if (!Vis[i])
        {
            DFS(i);
            Cnt++;
        }
        memset(f1,0,sizeof(f1));
		memset(f2,0,sizeof(f2));
		memset(f,0,sizeof(f));
		memset(bi,true,sizeof(bi));
		nn=mm=0;
		
		for (int i=1;i<=n;++i) addedge1(fa[i],i);
		
        /*
        while (~scanf("%d",&i))
        {
            if (P[i].incir)
            {
                printf("%d is in circle, tree: %d, circle id: %d\n",i,P[i].tree,P[i].cirid);
            }
            else
            {
                printf("%d is on root: %d, tree: %d, depth: %d\n",i,P[i].root,P[i].tree,P[i].dep);
            }
        }
        */
    }
}

Compiler output:
Main.java:1: error: illegal character: '#'
#include<cstdio>
^
Main.java:2: error: illegal character: '#'
#include<iostream>
^
Main.java:3: error: illegal character: '#'
#include<cstdlib>
^
Main.java:4: error: illegal character: '#'
#include<algorithm>
^
Main.java:5: error: illegal character: '#'
#include<vector>
^
Main.java:6: error: illegal character: '#'
#include<map>
^
Main.java:7: error: illegal character: '#'
#include<set>
^
Main.java:8: error: illegal character: '#'
#include<queue>
^
Main.java:9: error: illegal character: '#'
#include<stack>
^
Main.java:10: error: illegal character: '#'
#include<cstring>
^
Main.java:11: error: illegal character: '#'
#include<string>
^
Main.java:12: error: illegal character: '#'
#include<ctime>
^
Main.java:13: error: illegal character: '#'
#include<cmath>
^
Main.java:15: error: class, interface, enum, or record expected
typedef long long llong;
^
Main.java:17: error: class, interface, enum, or record expected
struct edge{
^
Main.java:19: error: class, interface, enum, or record expected
};
^
Main.java:20: error: class, interface, enum, or record expected
const int SN = 502000;
^
Main.java:21: error: class, interface, enum, or record expected
edge e1[SN*2],e2[SN*2];
^
Main.java:22: error: class, interface, enum, or record expected
int f1[SN],f[SN],f2[SN];
^
Main.java:23: error: class, interface, enum, or record expected
bool bi[SN];
^
Main.java:24: error: class, interface, enum, or record expected
int n,root,p1,p2,nn,mm;
^
Main.java:26: error: unnamed classes are a preview feature and are disabled by default.
int s(int k){
^
  (use --enable-preview to enable unnamed classes)
Main.java:55: error: class, interface, enum, or record expected
struct Node
^
Main.java:59: error: class, interface, enum, or record expected
    int cirid,dep;
    ^
Main.java:61: error: class, interface, enum, or record expected
}P[500010];
^
Main.java:62: error: class, interface, enum, or record expected
int Mark[500010],Cnt;
^
Main.java:63: error: class, interface, enum, or record expected
bool Vis[500010];
^
Main.java:120: error: illegal start of expression
    while (~scanf("%d%d",&N,&Q))
                         ^
Main.java:120: error: illegal start of expression
    while (~scanf("%d%d",&N,&Q))
                            ^
Main.java:124: error: illegal start of expression
            scanf("%d",&P[i].fa);
                       ^
30 errors