| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1349332 | edga1 | Tour (BOI25_tou) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
const int N=1000005;
vector<array<int,3>> g[N];
vector<int> atb;
set<int> s[N],f[N];
int e,beg,ie;
void dfs(int v, int c, int ed){
if(f[v].find(c)!=f[v].end()) return;
if(s[v].find(c)!=s[v].end()){
e=1;
beg=v;
ie=c;
atb.pb(ed);
return;
}
if(s[v].size()>=3) return;
s[v].insert(c);
for(auto a : g[v]){
int u=a[0],nc=a[1],ned=a[2];
if(nc==c) continue;
dfs(u,nc,ned);
if(e){
if(beg==v && c==ie) beg=-1
if(beg!=-1) atb.pb(ed);
break;
}
}
f[v].insert(c);
return;
}
void solve(){
int n,m;
cin>>n>>m;
for(int i=0; i<=n; i++){
s[i].clear();
f[i].clear();
g[i].clear();
}
vector<array<int,4>> edge(m);
for(int i=0; i<m; i++){
int x,y,c;
cin>>x>>y>>c;
g[x].pb({y,c,i+1});
}
for(int i=1; i<=n; i++){
g[0].pb({i,0,0});
}
e=0;
atb.clear();
dfs(0,1,0);
if(e){
cout<<"YES\n"<<atb.size()<<' ';
for(int i=atb.size()-1; i>=0; i--) cout<<atb[i]<<' ';
cout<<'\n';
}else cout<<"NO\n";
return;
}
int main(){
FIO
int tc; cin>>tc;
while(tc--){
solve();
}
return 0;
}
