Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 20;
- vector<int> adj[N];
- int dfs(int index,vector<int>& visited) {
- // cout<<(index+1)<<endl;
- visited[index]=true;
- for(auto y:adj[index]) {
- if(visited[y]==false) {
- // cout<<"Setting "<<y<< " to be visited"<<endl;
- visited[y]=true;
- return 1 + dfs(y,visited);
- }
- }
- return 1;
- }
- int main() {
- // your code goes here
- int t;
- cin>>t;
- while(t--) {
- int n;
- cin>>n;
- vector<int> visited(n,0);
- int a[n];
- for(int i=0;i<n;i++) { cin>>a[i]; adj[i].clear(); }
- //Build the graph for it and then run dfs
- for(int i=0;i<n;i++) {
- for(int j=i+1;j<n;j++) {
- if(a[j]-a[i]<=2) {
- //Add edge
- adj[i].push_back(j);
- adj[j].push_back(i);
- }
- }
- }
- int ma=-1;
- int mi = 100000;
- for(int i=0;i<n;i++) {
- //Call dfs on each node
- if(visited[i]==false) {
- int count=dfs(i,visited);
- // cout<<"Starting at "<<i+1<<" we can infect at max "<<count<<" people "<<endl<<endl;
- ma = max(ma,count);
- mi = min(mi,count);
- }
- }
- cout<<mi<<" "<<ma<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement