import java.util.Scanner;
public class Test6 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner du=new Scanner(System.in);
int m=du.nextInt();
int n=du.nextInt();
int N=du.nextInt();
String str[] = new String [1000];
int count=0;
str[0]="";
for(int i=0;i<N;i++)
{
int x=du.nextInt();
int y=du.nextInt();
for(int j=0;j<=count;j++)
{
if(str[j].contains(" "+x+" ") && str[j].contains(" "+y+" "))
break;
else if(str[j].contains(" "+x+" ") && ! str[j].contains(" "+y+" "))
{
str[j]+=y+" ";
break;
}
else if(str[j].contains(" "+y+" ") && ! str[j].contains(" "+x+" "))
{
str[j]+=x+" ";
break;
}
else if( !str[j].contains(" "+y+" ") && ! str[j].contains(" "+x+" ") && j==count)
{
count++;
j++;
str[count]=" "+x+" "+y+" ";
break;
}
}
}
for(int i=1;i<=m*n;i++)
{
for(int j=0;j<=count;j++)
{
if(str[j].contains(" "+i+" "))
{
break;
}
if(j==count)
{
count++;
str[count]=" "+i+" ";
}
}
}
System.out.println(count);
for(int i=0;i<=count;i++)
System.out.println(str[i]);
}
}
合根植物 蓝桥杯Java
最新推荐文章于 2025-04-22 13:22:37 发布