forked from KKSpro/cpp-programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
COVID19B.cpp
84 lines (69 loc) · 1.53 KB
/
COVID19B.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
#include<bits/stdc++.h>
#define ll long long;
using namespace std;
#define MAX 6
// Adjacency list representation of tree
vector<int> adj[MAX];
// Visited array to keep track visited
// nodes on tour
int vis[MAX];
// Array to store Euler Tour
// Function to add edges to tree
void add_edge(int u, int v)
{
adj[u].push_back(v);
adj[v].push_back(u);
}
// Function to store Euler Tour of tree
void eulerTree(int u)
{
vis[u] = 1;
for (auto it : adj[u]) {
if (!vis[it]) {
eulerTree(it);
}
}
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int arr[n+1];
for(int j=1;j<=n;j++)
{
adj[j].clear();
}
for(int i=1;i<=n;i++)cin>>arr[i];
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
if(arr[i]>arr[j])
add_edge(i,j);
}
}
vector<int> ans;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
vis[j]=0;
}
eulerTree(i);
int cnt=0;
for(int j=1;j<=n;j++)
{
if(vis[j]==1)
cnt++;
}
ans.push_back(cnt);
}
int minel = *min_element(ans.begin(),ans.end());
int maxel= *max_element(ans.begin(),ans.end());
cout<<minel<<" "<<maxel<<"\n";
}
}