[Offer收割]编程练习赛14 register

Ended

Participants:574

Verdict:Accepted
Score:100 / 100
Submitted:2017-04-16 14:04:59

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 <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
bool isValid(pair<int, int> node, int idx) {
    if (idx == 1) return node.first > 0 && node.second == 0;
    else return node.first >= 0 && node.second == 1;
}
int main()
{
    int n;
    cin >> n;
    vector<pair<int, int> > node(n + 1, make_pair(0, 0));
    vector<pair<int, int> > line(n - 1);
    int a, b;
    for (int i = 1; i < n; i++) {
        cin >> a >> b;
        node[a] = make_pair(node[a].first + 1, node[a].second);
        node[b] = make_pair(node[b].first, node[b].second + 1);
        line[i - 1] = make_pair(a, b);
    }
    for (int i = 1; i < n; i++) {
        a = line[i - 1].first;
        b = line[i - 1].second;
        if (isValid(make_pair(node[a].first - 1, node[a].second), a) &&
            isValid(make_pair(node[b].first, node[b].second - 1), b)) {
            cout << i << " ";
        }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX