Question : “https://cses.fi/problemset/task/1680/”

My solution -

```
lli dist[MAX];
lli parent[MAX];
int vis[MAX];
vi adj[MAX];
void dfs(lli src , lli lvl)
{
vis[src]=1;
dist[src] = lvl;
for(auto xt : adj[src])
{
if(!vis[xt])
{
parent[xt] = src;
dfs(xt , lvl+1);
}
else
{
if(dist[xt] < dist[src]+1)
{
dist[xt] = dist[src]+1;
parent[xt] = src;
}
}
}
}
int main(){
fastio
lli t=1;
//cin>>t;
chandan2();
while(t--) {
lli n,m;
cin>>n>>m;
loop(i,m)
{
lli x,y;
cin>>x>>y;
adj[x].pb(y);
}
dfs(1,0);
if(dist[n]==0)
print("IMPOSSIBLE");
else
{
vi ans;
ans.pb(n);
while(n!=1)
{
n = parent[n];
ans.pb(n);
}
reverse(all(ans));
print(sz(ans));
printvec(ans);
}
}
return 0;
}
```

I just did dfs and if already visited node occurs then change its parent if and only if the current distance is more , it shows WA in 3 TC’s and they are very big .