UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212774#3829. Cwangliwen12345600ms0kbC++689b2024-10-20 10:58:022024-10-20 12:42:55

answer

#include<bits/stdc++.h>
using namespace std;
int m,n,y;
int fa[100005];
int d[100005];
vector<int> cl[100005];
void dfs(int x) {
    d[x]=d[fa[x]]+1;
    for(int i;i<=n;i++
	) {
        dfs(y);
    }
}
int LAC(int x,int y) {
    if(d[x]<d[y]) {
        swap(x,y);
    }
    while(d[x]>d[y]) {
        x=fa[x];
    }
    while(x!=y) {
        x=fa[x];
        y=fa[y];
    }
    return x;
}
int main() {
    cin>>n;
    for(int i=1,x,y;i<n;i++) {
        cin>>x>>y;
        cl[x].push_back(y);
        fa[y]=x;
    }
    dfs(1);
    cin>>m;
    while(m--) {
        int u,v;
        cin>>u>>v;
        cout<<LAC(u,v)<<"\n";
    }
    return 0;
}


Details

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 0
Memory Limit Exceeded

Test #1:

score: 0
Memory Limit Exceeded

input:

5
3 1
1 5
2 4
5 4

output:


result:


Subtask #2:

score: 0
Memory Limit Exceeded

Test #4:

score: 0
Memory Limit Exceeded

input:

100
63 38
17 33
44 12
9 66
21 98
2 49
68 67
75 42
78 25
92 6
67 17
90 19
48 51
83 9
20 94
68 4
64 58...

output:


result:


Subtask #3:

score: 0
Memory Limit Exceeded

Test #10:

score: 0
Memory Limit Exceeded

input:

1000
228 978
939 994
911 13
8 806
680 958
779 832
673 924
627 806
354 476
320 218
766 848
171 944
90...

output:


result:


Subtask #4:

score: 0
Memory Limit Exceeded

Test #16:

score: 0
Memory Limit Exceeded

input:

100000
44881 88880
79640 18741
56510 31493
27649 50461
7015 98523
26337 91384
17594 52397
37312 3409...

output:


result:


Subtask #5:

score: 0
Runtime Error

Test #22:

score: 0
Runtime Error

input:

1000000
198444 939986
569807 470692
847908 557044
739959 80274
772656 222835
832266 382872
267873 10...

output:


result: