| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 814706 | groshi | Jail (JOI22_jail) | C++17 | 1 ms | 340 KiB |
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>
#define int long long
using namespace std;
struct wi{
vector<int> Q;
int skoki[20];
int poziom=0;
vector<int> po;
int przed=0;
}*w;
int pocz[130000];
int kon[130000];
int mam[130000][2];
void pusc(int x)
{
int gdzie=0;
while(w[w[x].skoki[gdzie]].skoki[gdzie]!=0)
{
w[x].skoki[gdzie+1]=w[w[x].skoki[gdzie]].skoki[gdzie];
gdzie++;
}
}
void dfs(int x,int ojc)
{
w[x].poziom=w[ojc].poziom+1;
for(int i=0;i<w[x].Q.size();i++)
{
int pom=w[x].Q[i];
if(pom==ojc)
continue;
w[pom].skoki[0]=x;
pusc(pom);
dfs(pom,x);
}
}
int lca(int x,int y)
{
if(w[x].poziom>w[y].poziom)
swap(x,y);
for(int i=19;i>=0;i--)
if(w[w[y].skoki[i]].poziom>=w[x].poziom)
y=w[y].skoki[i];
if(x==y)
return x;
for(int i=19;i>=0;i--)
if(w[x].skoki[i]!=w[y].skoki[i])
x=w[x].skoki[i],y=w[y].skoki[i];
return w[x].skoki[0];
}
void lec(int x,int y,int kto)
{
while(x!=y)
{
if(pocz[x]!=0 && pocz[x]!=kto)
{
w[kto].przed++;
w[pocz[x]].po.push_back(kto);
}
if(kon[x]!=0 && kon[x]!=kto)
{
w[kto].po.push_back(kon[x]);
w[kon[x]].przed++;
}
x=w[x].skoki[0];
}
}
int32_t main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int zap;
cin>>zap;
while(zap--)
{
int n,x,y;
cin>>n;
w=new wi[n+3];
for(int i=1;i<n;i++)
{
cin>>x>>y;
w[x].Q.push_back(y);
w[y].Q.push_back(x);
}
dfs(1,0);
int m;
cin>>m;
for(int i=1;i<=m;i++)
{
cin>>x>>y;
pocz[x]=i;
kon[y]=i;
mam[i][0]=x;
mam[i][1]=y;
}
for(int i=1;i<=m;i++)
{
x=mam[i][0];
y=mam[i][1];
int lcaa=lca(x,y);
lec(x,lcaa,i);
lec(y,lcaa,i);
}
int ilu=0;
vector<int> mam;
for(int i=1;i<=m;i++)
if(w[i].przed==0)
mam.push_back(i);
while(mam.size())
{
int x=mam.back();
mam.pop_back();
ilu++;
for(int i=0;i<w[x].po.size();i++)
{
w[w[x].po[i]].przed--;
if(w[w[x].po[i]].przed==0)
mam.push_back(w[x].po[i]);
}
}
if(ilu==m)
cout<<"Yes\n";
else cout<<"No\n";
}
return 0;
}Compilation message (stderr)
| # | 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... | ||||
