Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- /**
- * Created by U_LIVT33513 on 16.04.2016.
- */
- public class Ex_1_2 {
- public static void main(String args[])
- {
- int n,m,buff1,buff2;//n-вершины m-связи
- Scanner sc=new Scanner(System.in);
- n=sc.nextInt();
- m=sc.nextInt();
- //создать и иницилизировать список смежности
- ArrayList<Integer> edges[];
- edges=new ArrayList[n+1];
- for (int i=1;i<=n;i++) {
- edges[i] = new ArrayList<Integer>();
- }
- //смчитать связи , записать в список смежности
- for (int i=0;i<m;i++)
- {
- buff1=sc.nextInt();
- buff2=sc.nextInt();
- edges[buff1].add(buff2);
- edges[buff2].add(buff1);
- }
- //вывести кол-во связей для каждой вершины
- for(int i=1;i<=n;i++)
- {
- System.out.print(edges[i].size()+" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement