コード例 #1
0
ファイル: cachedtexture.cpp プロジェクト: Cav098/blitz3d
CachedTexture::CachedTexture( const string &f_,int flags,int w,int h,int first,int cnt ){
	string f=f_;
	if( f.substr(0,2)==".\\" ) f=f.substr(2);
	if( path.size() ){
		string t=path+tolower( filenamefile( f ) );
		if( rep=findRep( t,flags,w,h,first,cnt ) ) return;
		rep=d_new Rep( t,flags,w,h,first,cnt );
		if( rep->frames.size() ){
			rep_set.insert( rep );
			return;
		}
		delete rep;
	}
	string t=tolower( fullfilename( f ) );
	if( rep=findRep( t,flags,w,h,first,cnt ) ) return;
	rep=d_new Rep( t,flags,w,h,first,cnt );
	rep_set.insert( rep );
}
int countComponents(int n, vector<pair<int, int>>& edges) {
    vector<int> rep(n, 0);
    
    //initialization
    for (int i = 0; i < n; i++)
        rep[i] = i;
    
    //Union
    for (int i = 0; i < edges.size(); i++) {
        int rep1 = findRep(rep, edges[i].first);
        int rep2 = findRep(rep, edges[i].second);
        rep[rep1] = rep2;
    }
    
    // Count
    int count = 0;
    for (int i = 0; i < rep.size(); i++) {
        if (rep[i] == i)
            count++;
    }
    return count;
}