Submission #53133622


Source Code Expand

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag, tree_order_statistics_node_update>oset; 
#define hi cout << "test\n" ;/////
#define ho cerr <<"test\n";
const int mod = 998244353;
#define all(x) x.begin() , x.end() 
#define sp(x) fixed<<setprecision(x)
#define  ll unsigned long long
const ll inf = 1e18 ; 
#define FastIO ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#ifndef ONLINE_JUDGE
#define dbg(x) cerr << #x <<" = "; _print(x); cerr << endl;
#else
#define dbg(x)
#endif
ll binpow(ll a, ll b) {if (b == 0)return 1; ll res = binpow(a, b / 2);if (b % 2) return res * res * a;else return res * res;}
ll expo(ll a, ll b, ll mod) {ll ans = 1; while (b > 0) {if (b & 1)ans = (ans * a) % mod; a = (a * a) % mod; b = b >> 1;} return ans;}
ll gcd(ll a, ll b) { return((b == 0) ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return (b / gcd(a, b)) * a; }
int max ( int a , int b ) {if ( a > b ) return a ; return b ;}
int min ( int a , int b ){ if ( a < b )  return a ; return b ; }
void _print(auto t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(deque <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " "; } cerr << "]";}
template <class T> void _print(deque <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " "; } cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
template < typename T > void output (const vector<T> & vec ){  for(auto elem : vec) cout<<elem<<" ";cout <<"" ;}
//--------------------------------------------------------------- ------------------------------------------------------------------- 
#define int long long
const int MAX = 2e5 + 5;
typedef pair<long long, int> PII;
bool marked[MAX];
vector <PII> adj[MAX];
vector < int > vis ( MAX , false );

long long prim(int x)
{
    priority_queue<PII, vector<PII>, greater<PII> > Q;
    int y;
    long long minimumCost = 0;
    PII p;
    Q.push(make_pair(0, x));
    while(!Q.empty())
    {
        // Select the edge with minimum weight
        p = Q.top();
        Q.pop();
        x = p.second;
        // Checking for cycle
        if(marked[x] == true)
            continue;
        minimumCost += p.first;
        marked[x] = true;
        for(int i = 0;i < adj[x].size();++i)
        {
            y = adj[x][i].second;
            if(marked[y] == false)
                Q.push(adj[x][i]);
        }
    }
    return minimumCost;
}
void dfs ( int node ) {
    
        vis[node] = 1 ; 

        for ( auto & x : adj[node] ) {
              if ( vis[x.second]  ) continue ; 
              dfs ( x.second ) ;
        }
}
void solve(){ 
  
 
     int n , m ; 
     cin >> n >> m ; 


     for ( int i = 1 ; i <= m ; i++ ){

           int k , c ; 
           cin >> k >> c ; 

           vector < int > a ( k ) ; 
           for ( auto &x : a ) cin >> x ; 

           for ( int x = 0 ; x < k ;x++ ) {
              for ( int y = x + 1 ; y < k ; y++ ) {
                  adj[ a[x] ].push_back( { c , a[y] } ) ;
                  adj[ a[y] ].push_back( { c , a[x] } ) ;
              }
           }          

     }
     

     dfs ( 1 ) ; 
     for ( int i = 1 ; i <= n ; i++ ) {
        if ( vis[i] ) continue ; 

        cout << -1 ; 
        return ; 
     }
 

     int ans = prim( 1 ) ;
     cout << ans ;  
   

} 
//---------------------------------------------------------------------------------------------------------------------------------
int32_t main(){
 #ifndef ONLINE_JUDGE
    freopen("error.txt","w",stderr) ;
 #endif 

     FastIO ;
     int test = 1;
     int TestCases = 0 ; 

     if ( TestCases )
             cin>>test; 

     while(test--){
     solve(); 
      if(test>0)
        cout << endl; 
     }
 
 }          

Submission Info

Submission Time
Task E - Clique Connect
User Moorit
Language C++ 20 (gcc 12.2)
Score 0
Code Size 4645 Byte
Status TLE
Exec Time 2337 ms
Memory 2109448 KiB

Compile Error

Main.cpp: In function ‘long long int prim(long long int)’:
Main.cpp:65:25: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<std::pair<long long int, long long int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   65 |         for(int i = 0;i < adj[x].size();++i)
      |                       ~~^~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 450
Status
AC × 3
AC × 48
TLE × 4
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 02_random2_10.txt, 02_random2_11.txt, 02_random2_12.txt, 02_random2_13.txt, 02_random2_14.txt, 02_random2_15.txt, 02_random2_16.txt, 02_random2_17.txt, 02_random2_18.txt, 02_random2_19.txt, 02_random2_20.txt, 02_random2_21.txt, 02_random2_22.txt, 02_random2_23.txt, 02_random2_24.txt, 02_random2_25.txt, 02_random2_26.txt, 02_random2_27.txt, 02_random2_28.txt, 02_random2_29.txt, 02_random2_30.txt, 02_random2_31.txt, 02_random2_32.txt, 02_random2_33.txt, 02_random2_34.txt, 02_random2_35.txt, 02_random2_36.txt, 02_random2_37.txt, 02_random2_38.txt, 02_random2_39.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 3 ms 4480 KiB
00_sample_01.txt AC 3 ms 4680 KiB
00_sample_02.txt AC 3 ms 4508 KiB
01_random_00.txt AC 271 ms 106160 KiB
01_random_01.txt AC 210 ms 56436 KiB
01_random_02.txt AC 191 ms 38556 KiB
01_random_03.txt AC 140 ms 25908 KiB
01_random_04.txt AC 170 ms 21364 KiB
02_random2_00.txt TLE 2219 ms 193204 KiB
02_random2_01.txt TLE 2221 ms 193116 KiB
02_random2_02.txt AC 1391 ms 193728 KiB
02_random2_03.txt AC 1254 ms 193464 KiB
02_random2_04.txt AC 1244 ms 193724 KiB
02_random2_05.txt AC 1099 ms 101908 KiB
02_random2_06.txt AC 1055 ms 101900 KiB
02_random2_07.txt AC 695 ms 101852 KiB
02_random2_08.txt AC 681 ms 101964 KiB
02_random2_09.txt AC 676 ms 101756 KiB
02_random2_10.txt AC 680 ms 67592 KiB
02_random2_11.txt AC 654 ms 67660 KiB
02_random2_12.txt AC 487 ms 67572 KiB
02_random2_13.txt AC 472 ms 67640 KiB
02_random2_14.txt AC 473 ms 67652 KiB
02_random2_15.txt AC 469 ms 53436 KiB
02_random2_16.txt AC 454 ms 53608 KiB
02_random2_17.txt AC 392 ms 53656 KiB
02_random2_18.txt AC 373 ms 53504 KiB
02_random2_19.txt AC 383 ms 53628 KiB
02_random2_20.txt AC 351 ms 40312 KiB
02_random2_21.txt AC 352 ms 40412 KiB
02_random2_22.txt AC 323 ms 40348 KiB
02_random2_23.txt AC 316 ms 40584 KiB
02_random2_24.txt AC 317 ms 40424 KiB
02_random2_25.txt AC 286 ms 33944 KiB
02_random2_26.txt AC 287 ms 31732 KiB
02_random2_27.txt AC 279 ms 31748 KiB
02_random2_28.txt AC 271 ms 31868 KiB
02_random2_29.txt AC 269 ms 31936 KiB
02_random2_30.txt AC 219 ms 26456 KiB
02_random2_31.txt AC 225 ms 25568 KiB
02_random2_32.txt AC 226 ms 25504 KiB
02_random2_33.txt AC 220 ms 25488 KiB
02_random2_34.txt AC 220 ms 25672 KiB
02_random2_35.txt AC 173 ms 20108 KiB
02_random2_36.txt AC 176 ms 20160 KiB
02_random2_37.txt AC 174 ms 20124 KiB
02_random2_38.txt AC 170 ms 20260 KiB
02_random2_39.txt AC 170 ms 20116 KiB
03_handmade_00.txt AC 3 ms 4496 KiB
03_handmade_01.txt TLE 2337 ms 2109448 KiB
03_handmade_02.txt TLE 2337 ms 2095200 KiB
03_handmade_03.txt AC 66 ms 24944 KiB