# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
50076 | chonka | Alkemija (COCI18_alkemija) | C++98 | 92 ms | 17368 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |