コード例 #1
0
ファイル: Traffic Flow.c プロジェクト: Cyborn13x/UVa-1
int main()
{
	int i;
	int j;
	int k;
	int l;
	int m;
	int n;
	int t;
	int x;
	int y;
	int MinMax;
      scanf("%d",&t);x=1;
      while(t--)
      {
      	scanf("%d %d",&n,&m);MinMax=20000000;
      	for(i=0;i<n;i++) parent[i]=i;
      	for(i=0;i<m;i++) scanf("%d %d %d",&list[i].u,&list[i].v,&list[i].w);
      	qsort(list,m,sizeof(edge),&cmp);
      	for(i=k=0;i<m && k<n-1;i++)
      	{
      		if(!IsUnion(list[i].u,list[i].v))
      		{
      		      MakeUnion(list[i].u,list[i].v);
      		      k++;
      		      if(list[i].w<MinMax) MinMax=list[i].w;
      		}
      	}
      	printf("Case #%d: %d\n",x++,MinMax);
      }
	return 0;
}
コード例 #2
0
ファイル: DS_QuickUnion_SlowFind.C プロジェクト: sidpka/repo
int main(){



int n;
printf("\nEnter the number of elements :  ");
scanf("%d",&n);
int *Array=MakeSet(n);

int i;

printf("\nInitially set :\n");

Traverse(Array,n);

printf("\nPress enter to make union\n");
getch();
int ch;
int parent,child;
while(1){
printf("\nEnter your choice \n");
printf("\n1.Union");
printf("\n2.Find");
printf("\n3.Traverse");
printf("\n4.Exit\n");
scanf("%d",&ch);

switch(ch){
case 1:
printf("\nEnter parent , child \n");
scanf("%d %d",&parent,&child);
MakeUnion(Array,parent,child,n);
break;

case 2:
printf("\nEnter an element to find root of : ");
scanf("%d",&child);
printf("\nParent of %d is :  %d\n",child,Array[child]);
break;
case 3:
Traverse(Array,n);
break;

case 4:
return 0;

}
getch();

}


return 0;
}
コード例 #3
0
ファイル: board.cpp プロジェクト: lukaszlew/MiMHex
inline void Board::MakeUnion(uint pos) {
	uint rep = MakeUnion(pos, pos + 1);
	rep = MakeUnion(rep, pos - 1);
	rep = MakeUnion(rep, pos - kBoardSizeAligned);
	rep = MakeUnion(rep, pos - kBoardSizeAligned + 1);
	rep = MakeUnion(rep, pos + kBoardSizeAligned);
	MakeUnion(rep, pos + kBoardSizeAligned - 1);
}
コード例 #4
0
ファイル: board.cpp プロジェクト: lukaszlew/MiMHex
inline void Board::PlayLegal (const Move& move) {
	ASSERT(IsValidMove(move));
	uint pos = move.GetLocation().GetPos();
	if (move.GetPlayer() == Player::First()) {
		_board[pos] = pos;
		MakeUnion(pos);
	} else {
		_board[pos] = -1;
	}
	uint fast_map_pos = _reverse_fast_field_map[pos];
	uint replace_pos = _fast_field_map[--_moves_left];
	_fast_field_map[fast_map_pos] = replace_pos;
	_reverse_fast_field_map[replace_pos] = fast_map_pos;
	_current = _current.Opponent();
}