天天看點

西南科技大學OJ題 有向圖的鄰接矩陣存儲頂點删除1071

有向圖的鄰接矩陣存儲頂點删除

 5000(ms)

 10000(kb)

 2261 / 4574

Tags: 有向圖

假設有向圖G采用鄰接矩陣存儲,要求删除某一個頂點i(包括與其相關連的邊)。

輸入

第一行第一個整數n表示頂點的個數(頂點編号為0到n-1),第二個數表示被删除的頂點編号,接下來是為一個n*n大小的整數矩陣,表示圖的鄰接關系。數字為0表示不鄰接,1表示鄰接。
           

輸出

新的鄰接矩陣,第一行表示頂點的個數;
第二行是剩餘的結點編号;
接下來是為一個(n-1)*(n-1)大小的整數矩陣。
           

樣例輸入

5 2
0 1 0 1 0
0 0 1 1 0
0 0 0 0 0
0 0 0 0 0
1 0 0 1 0
           

樣例輸出

4
0134
0110
0010
0000
1010
           
#include<stdio.h>
int map[100][100],n,m;
void CreateMap()//建立鄰接矩陣 
{
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) scanf("%d",&map[i][j]);
}
void DistMap()//輸出鄰接矩陣 
{
	for(int i=0;i<n;i++)
	{
		if(i!=m)
		{
			for(int j=0;j<n;j++)
			{
				if(j!=m)
				{
					printf("%d",map[i][j]);
				}
			}
			printf("\n");
		}
	}
}
int main()
{
	scanf("%d %d",&n,&m);
	CreateMap();
	printf("%d\n",n-1);
	for(int i=0;i<n;i++) if(i!=m) printf("%d",i);
	printf("\n");
	DistMap();
}