Submission #50076

#TimeUsernameProblemLanguageResultExecution timeMemory
50076chonkaAlkemija (COCI18_alkemija)C++98
80 / 80
92 ms17368 KiB
#include<iostream> #include<stdio.h> #include<queue> using namespace std ; #define MAXN 100007 int n , m ; bool fl[ MAXN ] ; vector < int > v[ MAXN ] ; int lft[ MAXN ] ; vector < int > aux[ MAXN ] ; void input ( ) { int k ; scanf ( "%d%d" , &n , &k ) ; int i , j ; while ( k -- ) { int x ; scanf ( "%d" , &x ) ; fl[ x ] = true ; } scanf ( "%d" , &m ) ; for ( i = 1 ; i <= m ; i ++ ) { int sz1 , sz2 ; scanf ( "%d%d" , &sz1 , &sz2 ) ; for ( j = 0 ; j < sz1 ; j ++ ) { int x ; scanf ( "%d" , &x ) ; if ( fl[ x ] == false ) { lft[ i ] ++ ; v[ x ].push_back ( i ) ; } } for ( j = 0 ; j < sz2 ; j ++ ) { int x ; scanf ( "%d" , &x ) ; aux[ i ].push_back ( x ) ; } } } void solve ( ) { queue < int > q ; while ( q.empty ( ) == false ) { q.pop ( ) ; } int i , j ; for ( i = 1 ; i <= m ; i ++ ) { if ( lft[ i ] == 0 ) { q.push ( i ) ; lft[ i ] = -1 ; } } while ( q.empty ( ) == false ) { int x = q.front ( ) ; q.pop ( ) ; int sz = aux[ x ].size ( ) ; for ( i = 0 ; i < sz ; i ++ ) { if ( fl[ aux[ x ][ i ] ] == false ) { fl[ aux[ x ][ i ] ] = true ; int g = v[ aux[ x ][ i ] ].size ( ) ; for ( j = 0 ; j < g ; j ++ ) { int h = v[ aux[ x ][ i ] ][ j ] ; lft[ h ] -- ; if ( lft[ h ] == 0 ) { lft[ h ] = -1 ; q.push ( h ) ; } } } } } int ans = 0 ; for ( i = 1 ; i <= n ; i ++ ) { ans += fl[ i ] ; } printf ( "%d\n" , ans ) ; for ( i = 1 ; i <= n ; i ++ ) { if ( fl[ i ] == true ) { printf ( "%d " , i ) ; } } printf ( "\n" ) ; } int main ( ) { input ( ) ; solve ( ) ; return 0 ; }

Compilation message (stderr)

alkemija.cpp: In function 'void input()':
alkemija.cpp:19:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ( "%d%d" , &n , &k ) ;
     ~~~~~~^~~~~~~~~~~~~~~~~~~~
alkemija.cpp:23:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ( "%d" , &x ) ;
         ~~~~~~^~~~~~~~~~~~~
alkemija.cpp:26:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ( "%d" , &m ) ;
     ~~~~~~^~~~~~~~~~~~~
alkemija.cpp:29:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ( "%d%d" , &sz1 , &sz2 ) ;
         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
alkemija.cpp:32:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf ( "%d" , &x ) ;
             ~~~~~~^~~~~~~~~~~~~
alkemija.cpp:37:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf ( "%d" , &x ) ;
             ~~~~~~^~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...