最近感觉自己基础太差存图除了二维矩阵就不会用别的了,二维矩阵又很容易MLE,恶补邻接表。自己写的邻接表,没看板子,反正能过,以后就用它了。
附代码:
#include <bits/stdc++.h>
using namespace std;
typedef struct l{
int point ;
l* next;
}dlb;
struct node{
dlb* head;
int n,m;
}ljjz[50000];
int A[5000][5000];
void add(char c,int pos,int pos2){
int t=c-'0';
if (pos2==0){
dlb* p=new dlb;
p->point=t; p->next=NULL;
ljjz[pos].head=p;
}
if(pos2!=0){
dlb* p=new dlb;
p->point=t; p->next=NULL;
dlb* node2=ljjz[pos].head;
while(node2->next!=NULL){
node2=node2->next;
}
node2->next=p;
}
}
signed main(){
int t; cin>>t;
getchar();
for(int i=0;i<t;i++){
char c; int k=0;
while((c=getchar())){
if(c=='\n') break;
if(c==' ') continue;
add(c,i,k); k++;
}
}
for(int i=0;i<t;i++){
dlb* node2=ljjz[i].head;
while(node2!=NULL){
A[i][node2->point]=1;
node2=node2->next;
}
}
for(int i=0;i<t;i++){
for(int j=0;j<t;j++){
cout<<A[i][j];
}
cout<<endl;
}
}