fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. #if !defined(LOCAL)
  9. ios_base::sync_with_stdio(0);
  10. cin.tie(0);
  11. cout.tie(0);
  12. #endif
  13. vector<vector <int>>linie;
  14. int wir,sas, drzewo_zrodlo, drzewo_cel ;
  15. cin >> wir>>sas;
  16. linie.resize(wir+1);
  17. for (int i=0; i<sas; i++){
  18. cin >> drzewo_zrodlo >> drzewo_cel;
  19. linie[drzewo_zrodlo].push_back(drzewo_cel);
  20. linie[drzewo_cel].push_back(drzewo_zrodlo);
  21. }
  22. for(int i=1; i<wir+1; i++){
  23. if (linie[i].size()==0){
  24. cout <<"Wiewior sam!"<< endl;
  25. }else{
  26. for (int j=0; j< linie[i].size();j++) {
  27. cout<<linie[i][j] << " ";
  28. }
  29. cout <<endl;
  30. }
  31. }
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5260KB
stdin
5 4
2 3
1 3
5 1
5 3
stdout
3 5 
3 
2 1 5 
Wiewior sam!
1 3