zoukankan      html  css  js  c++  java
  • JZOI1062 【USACO2013JAN】invite

    #include <bits/stdc++.h>
    #define ll long long
    #define INF 2147483647
    #define ll_INF 9223372036854775807
    using namespace std;
    inline int read() {
    	int x = 0,tmp = 1;char ch = getchar();
    	while( ch < '0' || ch > '9' ) {if ( ch == '-' ) tmp = -1; ch = getchar();}
    	while( ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar(); }
    	return x * tmp;
    }
    multiset< int >_group[25100];
    queue< int > Q;
    bool _flag[1100000];
    int main() {
    	memset( _flag, 0, sizeof( _flag ) );
    	int N = read(), G = read();
    	for( int i = 1 ; i <= G ; ++ i ) {
    		int k = read();
    		for( int j = 1 ; j <= k; ++ j ) _group[i].insert( read() );
    	}
    	Q.push( 1 );
    	int tot = 1;
    	_flag[1] = 1;
    	while( !Q.empty() ) {
    		int _now = Q.front();
    		Q.pop();
    		for( int i = 1 ; i <= G ; ++ i ) if( !_group[i].empty() ) {
    			auto _where = _group[i].lower_bound( _now );
    			if( *_where != _now ) continue; else _group[i].erase( _where );
    			if( _group[i].size() == 1 ) {
    				auto the_only = _group[i].begin();
    				Q.push( *the_only );
    				if( !_flag[(int)*the_only] ) tot ++, _flag[(int)*the_only] = 1;
    				_group[i].erase( *the_only );
    			}
    		}
    	}
    	printf( "%d
    ", tot );
    
    	return 0;
    }
    
  • 相关阅读:
    系统设计5:Google三剑客
    lintcode亚麻九题
    设计模式17:单例模式
    设计模式16:迭代器模式
    设计模式15:组合模式
    476. Number Complement
    561. Array Partition I
    627. Swap Salary
    617. Merge Two Binary Trees
    728. Self Dividing Numbers
  • 原文地址:https://www.cnblogs.com/ARZhu-NOIpAK/p/6636439.html
Copyright © 2011-2022 走看看