-
Notifications
You must be signed in to change notification settings - Fork 0
/
10859_2.cpp
68 lines (65 loc) · 1.2 KB
/
10859_2.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
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<sstream>
#include<utility>
#include<deque>
#include<list>
#include<set>
#include<cmath>
#include<cctype>
#include<algorithm>
#include<ctime>
using namespace std;
#define rep(i, s, n) for(int i = s; i < n; i++)
const int M = 2000;
const int maxn = 1005;
int t, n,m;
vector<int> roads[maxn];
int vis2[maxn];
int dfs(int junc, int f, int fa){
vis2[junc] = 1;
//junc doesnt have light
int x = 0;
if(f){
for(auto r: roads[junc])if(r!=fa){
x += dfs(r,0,junc);
}
if(fa!=-1) x++;
}
//junc has light;
int y = 0;
for(auto r: roads[junc])if(r!= fa){
y += dfs(r,1, junc);
}
y+=M;
if(!f&&fa!=-1)y++;
if(f&&x>y) return y;
else if(f&&x<=y) return x;
else return y;
}
int main(){
cin>>t;
while(t--){
cin>>n>>m;
rep(i,0,n) roads[i].clear();
rep(i,0,m) {
int a,b;
cin>>a>>b;
roads[a].push_back(b);
roads[b].push_back(a);
}
memset(vis2,0,sizeof vis2);
int p = 0, q = 0;
rep(i,0,n) if(!vis2[i]){
int ans = dfs(i, 1, -1);
p += ans/M;
q += ans%M;
}
cout<<p<<" "<<m-q<<" "<<q<<endl;
}
}