Submission #492558

#TimeUsernameProblemLanguageResultExecution timeMemory
492558cgiosyUsmjeri (COCI17_usmjeri)C++17
0 / 140
134 ms27288 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...