Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <fstream>
  2. #include <algorithm>
  3. using namespace std;
  4. ifstream fin ("listavecini.in");
  5. ofstream fout ("listavecini.out");
  6. int a[101][101],i,j,maxx,x,y,n;
  7. bool okx,oky;
  8. struct varf
  9. {
  10. int nrvec;
  11. int vec[100];
  12. }v[101];
  13.  
  14. int main()
  15. {
  16. fin>>n;
  17. while(fin>>x)
  18. {
  19. fin>>y;
  20. okx=true;
  21. oky=true;
  22. for(i=1;i<=v[x].nrvec;i++)
  23. if(y==v[x].vec[i])
  24. okx=false;
  25. for(i=1;i<=v[y].nrvec;i++)
  26. if(x==v[y].vec[i])
  27. oky=false;
  28. if(okx==true)
  29. {
  30. v[x].nrvec++;
  31. v[x].vec[v[x].nrvec]=y;
  32. }
  33. if(oky==true)
  34. {
  35. v[y].nrvec++;
  36. v[y].vec[v[y].nrvec]=x;
  37. }
  38. }
  39.  
  40. for(i=1;i<=n;i++)
  41. {
  42. fout << v[i].nrvec<<" ";
  43. sort(v[i].vec+1,v[i].vec+v[i].nrvec+1);
  44. for(j=1;j<=v[i].nrvec;j++)
  45. fout<<v[i].vec[j]<<" ";
  46. fout << endl;
  47. }
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement