Count the number of distinct edges using set based algo

So I have this set
1 3
1 4
2 4
3 1
6 2
3 5
3 6
4 2
1 3
4 4
6 2

now using sba or Set Based Algorithm I have to pair it out and towards the end find the size of the resulting set

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <set>

int main()
{
    std::pair<int, int> p1;
    std::pair<int, int> p2;
    std::pair<int, int> p3;
    std::pair<int, int> p4;

    p1 = std::make_pair(1, 5);
    p2 = std::make_pair(5, 1);
    p3 = std::make_pair(1, 5);
    p4 = std::make_pair(2, 3);

    std::set<std::pair<int, int> > edgeSet;
    edgeSet.insert(p1);
    edgeSet.insert(p2);
    edgeSet.insert(p3);
    edgeSet.insert(p4);

    // the following prints "# of inserted edges = 3", do you see why?
    std::cout << "# of inserted edges = " << edgeSet.size() << std::endl;
    
    return 0;
}


this is the code just reads the edges that's 3... that is when we input the code. But what if its in a file? how do I read from there and show the paired count and the time taken?


Also I have the file that works and reads any txt file..but how do i get the code from it?

https://www.dropbox.com/s/savgtrhkus7rm4s/edgecount?dl=0

this is the file..you have to run it as ./edgecount for it to work
Last edited on
Are you basically asking how to read input?
http://www.cplusplus.com/doc/tutorial/basic_io/
http://www.cplusplus.com/doc/tutorial/files/


You do have pairs (1 5) and (5 1). Isn't that one and the same edge? Or do they have directionality?
Topic archived. No new replies allowed.