int n , k , P; int A[MAXN]; voidsolve(){ cin >> n; for( int i = 1 ; i <= n ; ++ i ) scanf("%d",&A[i]); sort( A + 1 , A + 1 + n ); cout << unique( A + 1 , A + 1 + n ) - A - 1 << endl; } intmain(){ int T;cin >> T; while( T-- ) solve(); }
int n , k , P; int A[MAXN]; vector<int> G[MAXN], o; int deg[MAXN] , ans[MAXN]; voidsolve(){ cin >> n; for( int i = 1 , u , v ; i < n ; ++ i ) { scanf("%d%d",&u,&v) , G[u].push_back( i ) , G[v].push_back( i ); deg[u] ++ , deg[v] ++; } for( int i = 1 ; i <= n ; ++ i ) if( deg[i] == 1 ) o.push_back( i ); memset( ans , -1 , sizeof ans ); if( o.size() <= 2 ) { for( int i = 0 ; i < n - 1 ; ++ i ) printf("%d\n",i); } else { int cur = 0; for( int x : o ) { for( int v : G[x] ) ans[v] = cur; ++ cur; if( cur >= 3 ) break; } cur = 2; for( int i = 1 ; i < n ; ++ i ) { if( ans[i] == -1 ) printf("%d\n",++ cur); elseprintf("%d\n",ans[i]); } } } intmain(){ solve(); }
ll u , v , k; voidsolve( ){ cin >> u >> v; if( !u && !v ) returnputs("0") , void(); if( u + v & 1 ) returnputs("-1") , void(); if( u > v ) returnputs("-1") , void(); if( u == v ) returnprintf("1\n%lld\n",u),void(); ll t = ( v - u ) / 2; if( t & u ) { printf("3\n%lld %lld %lld\n",u , v - u >> 1 , v - u >> 1); } else { printf("2\n%lld %lld\n",u|t,t); } } signedmain(){ // int T;cin >> T;while( T-- ) solve(); solve(); }
ll n , m; vector<int> G[MAXN]; int vis[MAXN] , dep[MAXN] , d , fa[MAXN]; voiddfs( int u ){ vis[u] = 1; for( int v : G[u] ) { if( vis[v] && ( dep[u] - dep[v] + 1 ) >= d ) { vector<int> cyc; int x = u; while( x != v ) cyc.push_back( x ) , x = fa[x]; cyc.push_back( v ); puts("2"); printf("%d\n",cyc.size()); for( int t : cyc ) printf("%d ",t); exit( 0 ); } elseif( !vis[v] ) { fa[v] = u , dep[v] = dep[u] + 1; dfs( v ); } } } int cn[MAXN]; voidsolve( ){ cin >> n >> m; int u , v; rep( i , 1 , m ) { scanf("%d%d",&u,&v); G[u].pb( v ) , G[v].pb( u ); } d = sqrt( n ) - 1; while( d * d < n ) ++ d; dfs( 1 ); int t = d - 1; for( int i = 1 ; i <= n ; ++ i ) cn[dep[i] % t] ++; int ps = max_element( cn , cn + t ) - cn; puts("1"); vi ans; for( int i = 1 ; i <= n ; ++ i ) if( dep[i] % t == ps ) ans.pb( i ); ans.resize( d ); for( int x : ans ) printf("%d ",x); } signedmain(){ // int T;cin >> T;while( T-- ) solve(); solve(); }