hihoCoder太阁最新面经算法竞赛4 register

Ended

Participants:109

Verdict:Wrong Answer
Score:0 / 100
Submitted:2016-06-15 21:51:50

Lang:G++

Edit
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
#include <stdio.h>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std;
int main() {
    int T, M, N;
    scanf("%d", &T);
    while (T--) {
        scanf("%d%d", &N, &M);
        if (M != N-1) {
            printf("NO\n");
            continue;
        }
        map<int, set<int> > adj;
        for (int i = 0; i < M; i++) {
            int a, b;
            scanf("%d%d", &a, &b);
            adj[a].insert(b);
            adj[b].insert(a);
        }
        // find the node with 1 edges
        vector<int> leaves;
        for (map<int, set<int> >::iterator iter = adj.begin(); iter != adj.end(); ++iter) {
            int cnt = iter->second.size();
            if (cnt == 0) {
                printf("NO\n");
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX