Advertisement
Guest User

Untitled

a guest
May 24th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. import java.io.FileReader;
  2. import java.io.FileWriter;
  3. import java.io.IOException;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.util.Scanner;
  7.  
  8. public class Main implements Runnable {
  9. public static void main(String[] args) {
  10. new Thread(null, new Main(), "", 64 * 1024 * 1024).start();
  11. }
  12. public void run() {
  13. try (Scanner sc = new Scanner(new FileReader("C:\\Users\\kovic\\Desktop\\Common\\src\\input.txt"));
  14. FileWriter fw = new FileWriter("C:\\Users\\kovic\\Desktop\\Common\\src\\output.txt")) {
  15. int n, m, first, second, size;
  16. n = sc.nextInt();
  17. m = sc.nextInt();
  18. List<Integer> [] versh = new ArrayList[n];
  19. for (int i = 0; i < n; ++i){
  20. versh[i] = new ArrayList<>();
  21. }
  22. for (int i = 0; i < m; ++i) {
  23. first = sc.nextInt();
  24. second = sc.nextInt();
  25. versh[first - 1].add(second);
  26. versh[second - 1].add(first);
  27. }
  28. for (int i = 0; i < n; ++i){
  29. size = versh[i].size();
  30. fw.write(String.valueOf(size));
  31. for (int j = 0; j < size; ++j){
  32. fw.write(" " + String.valueOf(versh[i].get(j)));
  33. }
  34. fw.write('\n');
  35. }
  36. } catch (IOException e1) {
  37. e1.printStackTrace();
  38. }
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement