-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1835.cpp
More file actions
42 lines (39 loc) · 801 Bytes
/
1835.cpp
File metadata and controls
42 lines (39 loc) · 801 Bytes
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
#include <iostream>
#define MAX 110
#include <vector>
#include <cstring>
using namespace std;
int states[MAX];
vector<int> v[MAX];
void bfs(int a){
states[a]=1;
for(auto it : v[a]){
if(states[it]==0)
bfs(it);
}
}
int main(){
int t, n, m, a, b;
scanf("%d", &t);
for(int o=1; o<=t; o++){
scanf("%d", &n);
memset(states, 0, sizeof states);
for(int i=0; i<MAX; i++) v[i].clear();
scanf("%d", &m);
while(m--){
scanf("%d %d", &a, &b);
v[a].push_back(b);
v[b].push_back(a);
}
int c = 0;
for(int k=1; k<=n; k++){
if(states[k]==0){
bfs(k);
c++;
}
}
if(c==1) printf("Caso #%d: a promessa foi cumprida\n", o);
else printf("Caso #%d: ainda falta(m) %d estrada(s)\n", o, c-1);
}
return 0;
}