Submission #566907

# Submission time Handle Problem Language Result Execution time Memory
566907 2022-05-23T05:57:11 Z jamezzz Jail (JOI22_jail) C++17
5 / 100
18 ms 11868 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#define getchar_unlocked getchar
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define li 2*i+1
#define ri 2*i+2
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
#define disc(x) sort(all(x));x.resize(unique(all(x))-x.begin());
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));

#define mod 1000000007

inline int rd(){
	int x=0;
	char ch=getchar_unlocked();
	while(!(ch&16))ch=getchar();//keep reading while current character is whitespace
    while(ch&16){//this will break when ‘\n’ or ‘ ‘ is encountered
		x=(x<<3)+(x<<1)+(ch&15);
		ch=getchar_unlocked();
	}
	return x;
}

#define maxn 120005

int n,m,s[maxn],t[maxn],sid[maxn],tid[maxn],deg[maxn];
int par[maxn],dep[maxn],cnt,pre[maxn],pst[maxn];
vi AL[maxn];
vector<iii> upds[maxn];
vi AL2[maxn],AL3[maxn];

void dfs(int u){
	pre[u]=cnt++;
	for(int v:AL[u]){
		if(v==par[u])continue;
		par[v]=u;
		dep[v]=dep[u]+1;
		dfs(v);
	}
	pst[u]=cnt-1;
}

int lz[4*maxn];
ii seg[4*maxn];

void init(int i,int s,int e){
	seg[i]={0,s};
	lz[i]=0;
	int m=(s+e)>>1;
	if(s!=e)init(li,s,m),init(ri,m+1,e);
}

void ppo(int i,int s,int e){
	seg[i].fi+=lz[i];
	if(s!=e){
		lz[li]+=lz[i];
		lz[ri]+=lz[i];
	}
	lz[i]=0;
}

void add(int i,int s,int e,int x,int y,int v){
	if(s==x&&e==y){
		lz[i]+=v;return;
	}
	int m=(s+e)>>1;
	if(y<=m)add(li,s,m,x,y,v);
	else if(x>m)add(ri,m+1,e,x,y,v);
	else add(li,s,m,x,m,v),add(ri,m+1,e,m+1,y,v);
	ppo(li,s,m);ppo(ri,m+1,e);
	seg[i]=min(seg[li],seg[ri]);
}

void add(int x,int y,int v){
	add(0,0,n-1,x,y,v);
}

ii qry(int i,int s,int e,int x,int y){
	ppo(i,s,m);
	if(s==x&&e==y)return seg[i];
	int m=(s+e)>>1;
	if(y<=m)return qry(li,s,m,x,y);
	if(x>m)return qry(ri,m+1,e,x,y);
	return min(qry(li,s,m,x,m),qry(ri,m+1,e,m+1,y));
}

ii qry(int x,int y){
	return qry(0,0,n-1,x,y);
}

int main(){
	int tc;sf("%d",&tc);
	while(tc--){
		sf("%d",&n);
		cnt=0;
		for(int i=1;i<=n;++i){
			sid[i]=tid[i]=-1;
			par[i]=0;
			AL[i].clear();
			upds[i].clear();
		}
		for(int i=0;i<m;++i){
			AL2[i].clear();
			AL3[i].clear();
		}
		
		for(int i=0;i<n-1;++i){
			int a,b;sf("%d%d",&a,&b);
			AL[a].pb(b);AL[b].pb(a);
		}
		sf("%d",&m);
		for(int i=0;i<m;++i){
			sf("%d%d",&s[i],&t[i]);
			sid[s[i]]=i;
			tid[t[i]]=i;
		}
		dfs(1);
		
		//AL2[u] -> v means v has to come before u
		for(int i=0;i<m;++i){
			int u=s[i],v=t[i];
			while(u!=v){
				if(dep[u]<dep[v])swap(u,v);
				if(sid[u]!=-1&&sid[u]!=i){
					AL2[i].pb(sid[u]);
					AL3[sid[u]].pb(i);
				}
				if(tid[u]!=-1&&tid[u]!=i){
					AL2[tid[u]].pb(i);
					AL3[i].pb(tid[u]);
				}
				u=par[u];
			}
			if(sid[v]!=-1&&sid[v]!=i){
				AL2[i].pb(sid[v]);
				AL3[sid[v]].pb(i);
			}
			if(tid[v]!=-1&&tid[v]!=i){
				AL2[tid[v]].pb(i);
				AL3[i].pb(tid[v]);
			}
		}
		
		vector<int> v;
		for(int i=0;i<m;++i){
			disc(AL2[i]);
			deg[i]=AL2[i].size();
			if(deg[i]==0)v.pb(i);
		}
		
		int proc=0;
		while(!v.empty()){
			int x=v.back();
			v.pop_back();
			++proc;
			for(int y:AL3[x]){
				--deg[y];
				if(deg[y]==0)v.pb(y);
			}
		}
		
		if(proc!=m)pf("No\n");
		else pf("Yes\n");
		
	}
}

Compilation message

jail.cpp: In function 'int main()':
jail.cpp:116:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |  int tc;sf("%d",&tc);
      |           ^
jail.cpp:118:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  118 |   sf("%d",&n);
      |     ^
jail.cpp:132:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  132 |    int a,b;sf("%d%d",&a,&b);
      |              ^
jail.cpp:135:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  135 |   sf("%d",&m);
      |     ^
jail.cpp:137:6: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  137 |    sf("%d%d",&s[i],&t[i]);
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11604 KB Output is correct
2 Correct 8 ms 11592 KB Output is correct
3 Correct 6 ms 11604 KB Output is correct
4 Incorrect 16 ms 11868 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11552 KB Output is correct
2 Correct 6 ms 11604 KB Output is correct
3 Correct 8 ms 11604 KB Output is correct
4 Correct 8 ms 11604 KB Output is correct
5 Correct 8 ms 11604 KB Output is correct
6 Correct 10 ms 11604 KB Output is correct
7 Correct 8 ms 11604 KB Output is correct
8 Correct 7 ms 11604 KB Output is correct
9 Correct 9 ms 11604 KB Output is correct
10 Correct 7 ms 11600 KB Output is correct
11 Correct 8 ms 11604 KB Output is correct
12 Correct 7 ms 11608 KB Output is correct
13 Correct 7 ms 11608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11552 KB Output is correct
2 Correct 6 ms 11604 KB Output is correct
3 Correct 8 ms 11604 KB Output is correct
4 Correct 8 ms 11604 KB Output is correct
5 Correct 8 ms 11604 KB Output is correct
6 Correct 10 ms 11604 KB Output is correct
7 Correct 8 ms 11604 KB Output is correct
8 Correct 7 ms 11604 KB Output is correct
9 Correct 9 ms 11604 KB Output is correct
10 Correct 7 ms 11600 KB Output is correct
11 Correct 8 ms 11604 KB Output is correct
12 Correct 7 ms 11608 KB Output is correct
13 Correct 7 ms 11608 KB Output is correct
14 Correct 7 ms 11596 KB Output is correct
15 Correct 7 ms 11604 KB Output is correct
16 Correct 8 ms 11612 KB Output is correct
17 Correct 9 ms 11676 KB Output is correct
18 Incorrect 8 ms 11604 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11552 KB Output is correct
2 Correct 6 ms 11604 KB Output is correct
3 Correct 8 ms 11604 KB Output is correct
4 Correct 8 ms 11604 KB Output is correct
5 Correct 8 ms 11604 KB Output is correct
6 Correct 10 ms 11604 KB Output is correct
7 Correct 8 ms 11604 KB Output is correct
8 Correct 7 ms 11604 KB Output is correct
9 Correct 9 ms 11604 KB Output is correct
10 Correct 7 ms 11600 KB Output is correct
11 Correct 8 ms 11604 KB Output is correct
12 Correct 7 ms 11608 KB Output is correct
13 Correct 7 ms 11608 KB Output is correct
14 Correct 7 ms 11596 KB Output is correct
15 Correct 7 ms 11604 KB Output is correct
16 Correct 8 ms 11612 KB Output is correct
17 Correct 9 ms 11676 KB Output is correct
18 Incorrect 8 ms 11604 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11552 KB Output is correct
2 Correct 6 ms 11604 KB Output is correct
3 Correct 8 ms 11604 KB Output is correct
4 Correct 8 ms 11604 KB Output is correct
5 Correct 8 ms 11604 KB Output is correct
6 Correct 10 ms 11604 KB Output is correct
7 Correct 8 ms 11604 KB Output is correct
8 Correct 7 ms 11604 KB Output is correct
9 Correct 9 ms 11604 KB Output is correct
10 Correct 7 ms 11600 KB Output is correct
11 Correct 8 ms 11604 KB Output is correct
12 Correct 7 ms 11608 KB Output is correct
13 Correct 7 ms 11608 KB Output is correct
14 Correct 7 ms 11596 KB Output is correct
15 Correct 7 ms 11604 KB Output is correct
16 Correct 8 ms 11612 KB Output is correct
17 Correct 9 ms 11676 KB Output is correct
18 Incorrect 8 ms 11604 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11604 KB Output is correct
2 Correct 6 ms 11604 KB Output is correct
3 Correct 7 ms 11584 KB Output is correct
4 Correct 7 ms 11592 KB Output is correct
5 Incorrect 18 ms 11732 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11604 KB Output is correct
2 Correct 8 ms 11592 KB Output is correct
3 Correct 6 ms 11604 KB Output is correct
4 Incorrect 16 ms 11868 KB Output isn't correct
5 Halted 0 ms 0 KB -