Submission #670338

# Submission time Handle Problem Language Result Execution time Memory
670338 2022-12-08T17:14:34 Z MilosMilutinovic Jail (JOI22_jail) C++17
0 / 100
1352 ms 13960 KB
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<cassert>
#define pb push_back
#define mk make_pair
using namespace std;
int n,m,go[120005][22],dep[120005],s[505],t[505],dfn[120005],dfo[120005],T;
vector<int> g[120005];
void dfs(int v,int pr)
{
	dep[v]=dep[pr]+1;go[v][0]=pr;dfn[v]=++T;
	for(int u:g[v])if(u!=pr)dfs(u,v);
	dfo[v]=T;
}
bool in(int x,int y){return dfn[x]<=dfn[y]&&dfo[y]<=dfo[x];}
int lca(int u,int v)
{
	int x=u;while(!in(x,v))x=go[x][0];return x;
	/*if(dep[u]<dep[v])swap(u,v);
	for(int i=19;i>=0;i--)if(dep[go[u][i]]>=dep[v])u=go[u][i];
	assert(u!=0);
	if(u==v)return u;
	assert(dep[u]==dep[v]);
	for(int i=19;i>=0;i--)if(go[u][i]!=go[v][i])u=go[u][i],v=go[v][i];
	assert(go[u][0]!=0);
	return go[u][0];*/
}
int deg[505];vector<int> e[505];
void init()
{
	T=0;
	for(int i=1;i<=120000;i++)g[i].clear(),dep[i]=0;
	for(int i=1;i<=120000;i++)for(int j=0;j<20;j++)go[i][j]=0;
	for(int i=1;i<=500;i++)deg[i]=0,e[i].clear();
}
void adde(int x,int y){deg[y]++;e[x].pb(y);}
bool on(int x,int y,int z){int l=lca(x,y);return in(l,z)&&(in(z,x)||in(z,y));}
int qu[505],qsz;
void solve()
{
	init();scanf("%d",&n);
	for(int i=1,u,v;i<n;i++)scanf("%d%d",&u,&v),g[u].pb(v),g[v].pb(u);
	dfs(1,0);
	for(int j=1;j<20;j++)for(int i=1;i<=n;i++)go[i][j]=go[go[i][j-1]][j-1];
	scanf("%d",&m);
	for(int i=1;i<=m;i++)scanf("%d%d",&s[i],&t[i]);
	for(int i=1;i<=m;i++)for(int j=1;j<=m;j++)if(i!=j&&on(s[i],t[i],s[j]))adde(j,i);
	qsz=0;for(int i=1;i<=m;i++)if(deg[i]==0)qu[++qsz]=i;
	for(int i=1;i<=qsz;i++)for(int j:e[qu[i]]){
		deg[j]--;
		if(deg[j]==0)qu[++qsz]=j;
		assert(deg[j]>=0);
	}
	bool ok=1;for(int i=1;i<=m;i++)ok&=(deg[i]==0);
	printf(ok?"Yes\n":"No\n");
}
int main()
{
	int t;scanf("%d",&t);
	while(t--)solve();
	return 0;
}

Compilation message

jail.cpp: In function 'void solve()':
jail.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |  init();scanf("%d",&n);
      |         ~~~~~^~~~~~~~~
jail.cpp:54:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |  for(int i=1,u,v;i<n;i++)scanf("%d%d",&u,&v),g[u].pb(v),g[v].pb(u);
      |                          ~~~~~^~~~~~~~~~~~~~
jail.cpp:57:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |  scanf("%d",&m);
      |  ~~~~~^~~~~~~~~
jail.cpp:58:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |  for(int i=1;i<=m;i++)scanf("%d%d",&s[i],&t[i]);
      |                       ~~~~~^~~~~~~~~~~~~~~~~~~~
jail.cpp: In function 'int main()':
jail.cpp:71:13: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |  int t;scanf("%d",&t);
      |        ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 13908 KB Output is correct
2 Correct 9 ms 13952 KB Output is correct
3 Correct 6 ms 13908 KB Output is correct
4 Incorrect 608 ms 13940 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 13908 KB Output is correct
2 Correct 6 ms 13908 KB Output is correct
3 Incorrect 32 ms 13908 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 13908 KB Output is correct
2 Correct 6 ms 13908 KB Output is correct
3 Incorrect 32 ms 13908 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 13908 KB Output is correct
2 Correct 6 ms 13908 KB Output is correct
3 Incorrect 32 ms 13908 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 13908 KB Output is correct
2 Correct 6 ms 13908 KB Output is correct
3 Incorrect 32 ms 13908 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 13952 KB Output is correct
2 Correct 8 ms 13960 KB Output is correct
3 Correct 9 ms 13868 KB Output is correct
4 Correct 7 ms 13956 KB Output is correct
5 Incorrect 1352 ms 13936 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 13908 KB Output is correct
2 Correct 9 ms 13952 KB Output is correct
3 Correct 6 ms 13908 KB Output is correct
4 Incorrect 608 ms 13940 KB Output isn't correct
5 Halted 0 ms 0 KB -