Language: C++

#include <iostream>
#include <fstream>
#include <numeric>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <deque>
#include <bitset>
#include <cstring>
#include <sstream>
 
#define f first
#define s second
#define ll long long
#define ld long double
#define pb push_back
#define all(x) x.begin(),x.end()
#define mp make_pair
#define y0 eto
#define y1 mezhdy
#define y2 nami
#define left extermination
#define right dismemberment
 
using namespace std;
 
typedef pair<int,int> pii;
 
template <class T>void read(vector<T> &a,ll n){T x; a.clear();for(ll i=0;i<n;i++){cin>>x;a.pb(x);}}
template <class T>void write(vector<T> &a){for(T x : a) cout<<x<<" ";cout<<endl;}

const int N=405;

int n,m,Tmax;
int p[N];

map<pii,int> have;
vector<pair<int,pii> > orders;
vector<pair<int,pii> > e1;
int last_w;

int tm;

vector<pii> g[N];
int d[N];
int par[N];

vector<int> ans;

void prepare_dsu()
{
    for(int i=0;i<N;i++)
        p[i]=i;
}

int fnd(int u)
{
    if(u==p[u]) return u;
    return p[u]=fnd(p[u]);
}

void un(int a,int b)
{
    int u=fnd(a);
    int v=fnd(b);
    if(rand()&1) swap(u,v);
    if(u!=v)
        p[u]=v;
}


void refresh(int u)
{
    vector<pii> v;
    while(par[u]!=-1)
    {
        v.pb({u,par[u]});
        u=par[u];
    }
    
    for(int i=0;i<v.size();i++)
    {
        int a=v[i].f;
        int b=v[i].s;
        for(int j=0;j<have[{a,b}];j++)
            ans.pb(b);
    }
    
    for(int i=0;i<v.size();i++)
        swap(v[i].f,v[i].s);
    reverse(all(v));
    
    for(int i=0;i<v.size();i++)
    {
        int a=v[i].f;
        int b=v[i].s;
        for(int j=0;j<have[{a,b}];j++)
            ans.pb(b);
    }
}

void go1(int u,int p=-1)
{
    if(ans.size()>Tmax) return;
    
    tm++;
    if(u==1)
        tm=0;
    
    if(tm>100)
    {
        refresh(u);
        tm=0;
    }
    
    for(int i=0;i<g[u].size();i++)
    {
        if(g[u][i].f==p) continue;
        
        for(int j=0;j<g[u][i].s;j++)
            ans.pb(g[u][i].f);
        
        go1(g[u][i].f,u);
        
        for(int j=0;j<g[u][i].s;j++)
            ans.pb(u);
    }
    
}



void dfs(int u,int p=-1,int dst=0)
{
    d[u]=dst;
    par[u]=p;
    for(int i=0;i<g[u].size();i++)
        if(g[u][i].f!=p)
            dfs(g[u][i].f,u,dst+1);
}

void ride1()
{
    go1(1);
}


int main()
{
    ios_base::sync_with_stdio(0);
    //freopen("scripts/test.in", "r", stdin);
    //freopen("scripts/result.out", "w", stdout);
    
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        e1.pb(mp(c,mp(a,b)));
        have[{a,b}]=c;
    }
    
    cin>>Tmax;
    for(int i=0;i<Tmax;i++)
    {
        int Nnew;
        cin>>Nnew;
        while(Nnew--)
        {
            int id,x;
            cin>>id>>x;
            orders.pb(mp(i,mp(id,x)));
        }
    }
    prepare_dsu();
    sort(all(e1));
    
    for(int i=0;i<e1.size();i++)
    {
        int a=e1[i].s.f;
        int b=e1[i].s.s;
        int w=e1[i].f;
        if(fnd(a)!=fnd(b))
        {
            un(a,b);
            g[a].pb(mp(b,w));
            g[b].pb(mp(a,w));
            have[{a,b}]=w;
            have[{b,a}]=w;
        }
    }
    
    dfs(1);
    
    while(ans.size()<Tmax)
        ride1();
    
    while(ans.size()>Tmax)
        ans.pop_back();
    while(ans.size()<Tmax)
        ans.pb(-1);
    
    for(int i=0;i<ans.size();i++)
        cout<<ans[i]<<endl;
    
}



Compiler output:
a.cc: In function 'void go1(int, int)':
a.cc:112:5: error: reference to 'tm' is ambiguous
  112 |     tm++;
      |     ^~
In file included from /usr/include/time.h:39,
                 from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
                 from /usr/include/c++/14/ext/atomicity.h:35,
                 from /usr/include/c++/14/bits/ios_base.h:39,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:48:5: note:                 'int tm'
   48 | int tm;
      |     ^~
a.cc:114:9: error: reference to 'tm' is ambiguous
  114 |         tm=0;
      |         ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:48:5: note:                 'int tm'
   48 | int tm;
      |     ^~
a.cc:116:8: error: reference to 'tm' is ambiguous
  116 |     if(tm>100)
      |        ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:48:5: note:                 'int tm'
   48 | int tm;
      |     ^~
a.cc:119:9: error: reference to 'tm' is ambiguous
  119 |         tm=0;
      |         ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:48:5: note:                 'int tm'
   48 | int tm;
      |     ^~