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

Ended

Participants:405

Verdict:Time Limit Exceeded
Score:60 / 100
Submitted:2017-07-23 14:01:51

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 <queue>
#include <set>
using namespace std;
int solution(vector<int> &vect, int i, int j) {
    vector<int> v1 = { i };
    vector<int> v2 = { j };
    while (j > 0 && vect[j] != -1) {
        j = vect[j];
        v2.push_back(j);
    }
    while (i > 0 && vect[i] != -1) {
        i = vect[i];
        v1.push_back(i);
    }
    int p2 = v2.size() - 1;
    int p1 = v1.size() - 1;
    int p;
    while (p1 >= 0 && p2 >= 0 && v1[p1] == v2[p2]) {
        p = v1[p1];
        p1--; 
                p2--;
    }
    return p;
}
bool inter(vector<int> &v, int s, int t, int p1, int p2) {
    if (p2 == p1)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX