写出该图的邻接矩阵,建立无向图的邻接矩阵
用邻接矩阵表示法制作无向图用邻接矩阵表示法制作无向图g,依次输出各顶点的度。
输入格式:
输入的第1行被赋予了2个整数I(0I10 ),j ) j0 )分别是图表g的顶点数和边数。 输入第二个行为的顶点信息。 每个顶点只能用一个字符表示。 依次输入j行,然后输入每行与边相连的顶点。
输出格式:
按顺序输出各顶点的度,行尾没有最后的空间。
输入样例:
5 7
ABCDE
AB
AD
英国广播公司
坏的结局
CD
CE
DE
输出样例:
2 3 3 3 3
vector map set的基本使用
33558 www.Sina.com/# include iostream # include algorithm # includecstringusingnamespacestd; const int N=10000; int n,m; int g[N][N]; char str[15],st[3]; intfind(intx ) { int cont=0; for(intI=0; in; I ) { int y=str[i]; if(g ) x ) y )==1) cont; } return cont; (}int main ) ) { cinnm; cinstr; for(intI=0; im; I ) { cinst; int x=st[0]; int y=st[1]; g[x][y]=1; g[y][x]=1; }coutfind(str[0]; for(intI=1; in; I ) cout''find(str[I]; 返回0; }考试必须这样做# include iostream # include algorithm # include cstring # includemapusingnamespacestd; mapchar,int q; int n,m; int main () { cinnm; char str[15],st[3]; cinstr; for(intI=0; im; I ) { cinst; q[st[0]]; q[st[1]]; } coutq[str[0]]; for(intI=1; in; I ) cout' 'q[str[i]]; 返回0; }