Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // rasssschet.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- using namespace std;
- const int SIZE = 1000;
- int p[SIZE];
- bool usd[SIZE];
- int n, m, f, s, sravn, horda;
- int main()
- {
- ifstream fin("test4.txt");
- ofstream fout("rex.txt");
- fin >> n >> m;
- for (int i = 1; i <= n; i++){
- p[i] = i;
- }
- for (int i = 0; i < m; i++){
- fin >> f >> s;
- sravn = p[f];
- for (int j = 1; j <= n; j++){
- if (p[j] == sravn)
- p[j] = p[s];
- }
- }
- for (int i = 1; i <= n; i++){
- usd[p[i]] = true;
- }
- int count = 0;
- for (int i = 0; i <= n; i++){
- if (usd[i]) ++count;
- }
- horda = m - n + count;
- fout << horda << endl;
- fin.close();
- fout.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement