Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test case issue [Forwarding Emails (LOJ-1417)] #223

Open
Tanzimbn opened this issue Sep 12, 2024 · 0 comments
Open

Test case issue [Forwarding Emails (LOJ-1417)] #223

Tanzimbn opened this issue Sep 12, 2024 · 0 comments

Comments

@Tanzimbn
Copy link

https://lightoj.com/problem/forwarding-emails

Test case is missing which could give TLE for the tutorial solution.

#include<bits/stdc++.h>
using namespace std;
int vis[50005],dist[50005],adjacent[50005],cnt=0;
int dfs(int uu)
{
    vis[uu]=1;
    int vv=adjacent[uu];
    if(!vis[vv])
    {
        cnt++;
        dfs(vv);
    }
    vis[uu]=0;
    return dist[uu]=cnt;

}
main()
{   
    int ts,cs=1;
    scanf("%d",&ts);
    while(ts--)
    {
        int n,u,v,mx=0,ans=0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d",&u,&v);
            adjacent[u]=v;
        }
        memset(vis,0,sizeof(vis));
        memset(dist,-1,sizeof(dist));
        for(int i=1;i<=n; i++)
        {
            cnt=1;
            if(dist[i]==-1)
            {
                dfs(i);
                dist[i]=cnt;
            }
            if(cnt>mx)
            {
                mx=cnt;
                ans=i;
            }
        }

        printf("Case %d: %d\n",cs++,ans);
    }
}

Test case :

1
50000
1 2
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
...
...
49998 49997
49999 49998
50000 49999

I also can make number of test cases 20 and repeat the same graph 20 times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant