Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. // rasssschet.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <fstream>
  7.  
  8. using namespace std;
  9.  
  10. const int SIZE = 1000;
  11. int p[SIZE];
  12. bool usd[SIZE];
  13. int n, m, f, s, sravn, horda;
  14.  
  15. int main()
  16. {
  17. ifstream fin("test4.txt");
  18. ofstream fout("rex.txt");
  19.  
  20. fin >> n >> m;
  21. for (int i = 1; i <= n; i++){
  22. p[i] = i;
  23.  
  24. }
  25. for (int i = 0; i < m; i++){
  26. fin >> f >> s;
  27. sravn = p[f];
  28. for (int j = 1; j <= n; j++){
  29. if (p[j] == sravn)
  30. p[j] = p[s];
  31. }
  32. }
  33. for (int i = 1; i <= n; i++){
  34. usd[p[i]] = true;
  35. }
  36. int count = 0;
  37. for (int i = 0; i <= n; i++){
  38. if (usd[i]) ++count;
  39. }
  40. horda = m - n + count;
  41. fout << horda << endl;
  42. fin.close();
  43. fout.close();
  44.  
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement