-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtemp.cpp
107 lines (93 loc) · 2.03 KB
/
temp.cpp
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <ctime>
#include <cassert>
using namespace std; // }}}
int factorial(int n)
{
return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
}
void BFS(vector<vector<int> > pairs())
{/*
list<int> queue;
if(visited[s] == false)
{
cost += cl;
visited[s] = true;
queue.push_back(s);
}
list<int>::iterator i;
while(!queue.empty())
{
s = queue.front();
//cout << s << " ";
queue.pop_front();
for (i = pairs[s].begin(); i != pairs[s].end(); ++i)
{
if (!visited[*i])
{
visited[*i] = true;
queue.push_back(*i);
}
//cout <<"COST="<<cost<<endl;
}
}*/
}
int main()
{
int N, I;
cin >> N >> I;
vector<vector<int> > pairs(N);
for (int i = 0; i < I; ++i) {
int a, b;
cin >> a >> b;
pairs[a].push_back(b);
pairs[b].push_back(a);
}
long long result = 0;
/** Write code to compute the result using N,I,pairs **/
int s = 0;
bool *visited = new bool[N];
for(int i = 0; i < n; i++)
visited[i] = false;
if(visited[s] == false)
{
visited[s] = true;
queue.push_back(s);
}
list<int>::iterator i;
while(!queue.empty())
{
s = queue.front();
//cout << s << " ";
queue.pop_front();
for (i = pairs[s].begin(); i != pairs[s].end(); ++i)
{
if (!visited[*i])
{
visited[*i] = true;
queue.push_back(*i);
}
//cout <<"COST="<<cost<<endl;
}
cout << result << endl;
return 0;
}