Language: C++

#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;

char s[100005];
int next[100005][26];
int p[26];
int deep[100005],dir[100005];
int len;


void dfs(int i)
{
    if (deep[i]!=0)
        return ;
    for (int j=0;j<26;j++)
        if (next[i][j]==0)
            {
            dir[i]=j;
            deep[i]=1;
            return ;
            }

    int minn=1999999999;
    for (int j=0;j<26;j++)
        {
        dfs(next[i][j]);
        if (deep[next[i][j]]<minn)
            {
            minn=deep[next[i][j]];
            dir[i]=j;
            }
        }
    deep[i]=minn+1;
}

void work()
{
    dfs(0);
    int i=0;
    while (1)
        {
        printf ("%c",dir[i]+'a');
        if (next[i][dir[i]]==0) break;
        else i=next[i][dir[i]];
        }
}

int main()
{
    scanf ("%s",s+1);
    len=strlen(s+1);
    for (int i=len;i>=0;i--)
        {
        for (int j=0;j<26;j++)
            next[i][j]=p[j];
        p[s[i]-'a']=i;
        }
    work();
}


Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:18:13: error: reference to 'next' is ambiguous
   18 |         if (next[i][j]==0)
      |             ^~~~
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:5: note:                 'int next [100005][26]'
    7 | int next[100005][26];
      |     ^~~~
a.cc:28:13: error: reference to 'next' is ambiguous
   28 |         dfs(next[i][j]);
      |             ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:5: note:                 'int next [100005][26]'
    7 | int next[100005][26];
      |     ^~~~
a.cc:29:18: error: reference to 'next' is ambiguous
   29 |         if (deep[next[i][j]]<minn)
      |                  ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:5: note:                 'int next [100005][26]'
    7 | int next[100005][26];
      |     ^~~~
a.cc:31:23: error: reference to 'next' is ambiguous
   31 |             minn=deep[next[i][j]];
      |                       ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:5: note:                 'int next [100005][26]'
    7 | int next[100005][26];
      |     ^~~~
a.cc: In function 'void work()':
a.cc:45:13: error: reference to 'next' is ambiguous
   45 |         if (next[i][dir[i]]==0) break;
      |             ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:5: note:                 'int next [100005][26]'
    7 | int next[100005][26];
      |     ^~~~
a.cc:46:16: error: reference to 'next' is ambiguous
   46 |         else i=next[i][dir[i]];
      |                ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:5: note:                 'int next [100005][26]'
    7 | int next[100005][26];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:57:13: error: reference to 'next' is ambiguous
   57 |             next[i][j]=p[j];
      |             ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:7:5: note:                 'int next [100005][26]'
    7 | int next[100005][26];
      |     ^~~~