Submission #3951665


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
const int M=1e5+4;
vector<int>v[M];
int n,m,dp[M],par[M],ans;
void dfs(int u)
{
	//cout<<u<<endl;
	for(auto x:v[u])
	{
		if(dp[x]<dp[u]+1)
		{
			dp[x]=dp[u]+1;
			dfs(x);
		}
	}
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++) par[i]=-1;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		par[y]=x;
	}
	for(int i=1;i<=n;i++)
	{
		if(par[i]==-1)
		dfs(i);
	}
	for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
	cout<<ans;
	return 0;
}

Submission Info

Submission Time
Task G - Longest Path
User amit_ranjan
Language C++14 (GCC 5.4.1)
Score 0
Code Size 529 Byte
Status

Test Cases

Set Name Score / Max Score Test Cases
All 0 / 100 0_00, 0_01, 0_02, 1_00, 1_01, 1_02, 1_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12, 1_13, 1_14, 1_15, 1_16, 1_17, 1_18
Case Name Status Exec Time Memory
0_00 3 ms 2560 KB
0_01 3 ms 2560 KB
0_02 3 ms 2560 KB
1_00 3 ms 2560 KB
1_01 88 ms 9600 KB
1_02 67 ms 3200 KB
1_03 84 ms 5120 KB
1_04 82 ms 4224 KB
1_05 77 ms 3840 KB
1_06 73 ms 3584 KB
1_07 69 ms 3456 KB
1_08 69 ms 3328 KB
1_09 67 ms 3200 KB
1_10 64 ms 3200 KB
1_11
1_12
1_13
1_14
1_15 1992 ms 3712 KB
1_16
1_17
1_18