This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
constexpr int MOD=1e9+7;
int main() {
ios::sync_with_stdio(0);cin.tie(0);
int N, M;
cin>>N>>M;
int D[N], P[N], E[N*2], F[N*2], G[N]{};
for(int i=1; i<N; i++) {
int a, b;
cin>>a>>b; --a, --b;
E[i*2]=b, F[i*2]=G[a], G[a]=i*2;
E[i*2+1]=a, F[i*2+1]=G[b], G[b]=i*2+1;
}
function<void(int)> dfs=[&](int i) {
for(int e=G[i]; e; e=F[e]) if(int&j=E[e]; j!=P[i])
D[j]=D[i]+1, P[j]=i, dfs(j);
};
D[0]=1, P[0]=0; dfs(0);
function<int(int)> root=[&](int i) { return !D[i] ? P[i]=root(P[i]) : i; };
while(M--) {
int a, b;
cin>>a>>b; --a, --b;
for(a=root(a); a!=(b=root(b)); D[b]=0) if(D[a]>D[b]) swap(a, b);
}
int v=0;
cout<<v<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |