제출 #1343695

#제출 시각아이디문제언어결과실행 시간메모리
1343695ender_shayanTour (BOI25_tou)C++20
0 / 100
1 ms1096 KiB
#include <bits/stdc++.h>

using namespace std;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

typedef long long ll;
typedef long double	ld;
typedef pair<int, int>	pii  ;
typedef pair<ll, ll>	pll  ;
typedef vector<pii>     vii  ;
typedef vector<int>     veci ;
typedef vector<pll>     vll  ;
typedef vector<ll>      vecll;

// find_by_order             order_of_key

//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define F		        first
#define S		        second
#define pb		        push_back
#define endl            '\n'
#define Mp		        make_pair
#define all(x)          x.begin(), x.end()
#define debug(x)        cerr << #x << " = " << x << endl
#define set_dec(x)	    cout << fixed << setprecision(x);
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io         freopen("in.txt" , "r" , stdin) ; freopen("out.txt" , "w" , stdout);
#define lb              lower_bound
#define ub              upper_bound
#define for1(n)         for(int i=1;i<=n;i++)
#define for0(n)         for(int i=0;i<n;i++)
#define forn(n)         for(int i=n;i>0;i--)
#define pq              priority_queue <pii, vector<pii>, greater<pii>>


const int N=1e3+3;
int n,m,k;
vector<int>gg[N];
vector<int>vec,ans;
deque<int>g[N];
pair<pii,int>A[N];
map<int,int>vis[N];
void get_ans(int tt){
    for(tt--;tt<vec.size();tt++)ans.pb(vec[tt]);
}
void dfs(int v,int c){
    vis[v][c]=vec.size()+1;
    for(int i:gg[v]){
        // int i=g[v].back();
        if(A[i].S!=c){
            vec.pb(i);
            if(vis[A[i].F.S][A[i].S]==0)
                dfs(A[i].F.S,A[i].S);
            else if(vis[A[i].F.S][A[i].S]!=-1 && ans.size()==0){
                get_ans(vis[A[i].F.S][A[i].S]);
            }
            // if(g[v].size() && g[v].back()==i)
            //     g[v].pop_front();
            vec.pop_back();
            continue;
        }
        // i=g[v].front();
        // if(A[i].S!=c){
        //     vec.pb(i);
        //     if(vis[A[i].F.S][A[i].S]==0)
        //         dfs(A[i].F.S,A[i].S);
        //     else if(vis[A[i].F.S][A[i].S]!=-1 && ans.size()==0)
        //         get_ans(vis[A[i].F.S][A[i].S]);
        //     if(g[v].size() && g[v].front()==i)
        //         g[v].pop_front();
        //     vec.pop_back();
        //     continue;
        // }
        // break;
    }
    vis[v][c]=-1;

}
int main(){
    fast_io
    int T;cin>>T;
    while(T--){
        cin>>n>>m;
        for1(m){
            int u,v,c;cin>>u>>v>>c;
            A[i]={{u,v},c};
            gg[u].pb(i);
        }
        for1(n){
            sort(all(gg[i]));
            for(int x:gg[i])g[i].pb(x);
        }
        for1(m)if(vis[A[i].F.S][A[i].S]==0)dfs(A[i].F.S,A[i].S);
        if(ans.size()){
            cout<<"YES\n";
            cout<<ans.size()<<" ";
            for(int x:ans)cout<<x<<" ";cout<<endl;
        }
        else
            cout<<"NO\n";
        for1(n){
            vis[i].clear();
            gg[i].clear();
            g[i].clear();
        }
        ans.clear();

    }




}



#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...