답안 #22989

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22989 2017-05-01T02:54:45 Z model_code File Paths (BOI15_fil) C++11
100 / 100
216 ms 14280 KB
// Tomasz Syposz

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=(a);i<=(b);++i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define SORT(X) sort(X.begin(),X.end())
#define eb emplace_back
#define fi first
#define se second

int n,mxLen,slink;
vector<int> V[3001];
vector<pair<int,int> > Z[3001],Ans;
int Cy[2000001],L[3001],Zaz[1000001];
int Sc_null;

vector<int> D,Path;
void dziel(int a){
	D.clear();
	for(int i = 1; i*i <= a; i++) if(a%i==0){
		D.pb(i);
		D.pb(a/i);
	}
}

void update(int u, int Ld, int w){
  Cy[L[u]-Ld+slink] += w;
	FOR(v,SZ(V[u])) update(V[u][v],Ld,w);
}

void solve(int u){
	Path.pb(u);
	update(u,L[u],1);
	FOR(z, SZ(Z[u])){
		dziel(mxLen - L[u] - Z[u][z].fi);
		int tmp_ans = 0;
		FOR(d, SZ(D)){
			if(Cy[D[d]] > 0) tmp_ans = 1;
		}
		FOR(p, SZ(Path))  if(mxLen - (L[u]-L[Path[p]]+slink+Z[u][z].fi) >= 0)
			if(Zaz[mxLen - (L[u]-L[Path[p]]+slink+Z[u][z].fi)]) tmp_ans = 1;
    if(L[u]+Z[u][z].fi == mxLen) tmp_ans = 1;
		Ans.pb(mp(Z[u][z].se,tmp_ans));
	}
	FOR(v,SZ(V[u]))
		solve(V[u][v]);
	Path.pop_back();
	update(u,L[u],-1);
}

int main () {
	int m,k;
	Sc_null = scanf("%d%d%d%d",&n,&m,&k,&slink);
	slink++;
	mxLen = k;
	L[0] = 1;
	Zaz[1] = 1;
	FORI(i,n){
		int a,b;
		Sc_null =  scanf("%d%d",&a,&b);
		L[i] = b+1+L[a];
		Zaz[L[i]] = 1;
		V[a].pb(i);
	}

	FOR(i,m){
		int a,b;
		Sc_null = scanf("%d%d",&a,&b);
		Z[a].pb(mp(b,i));
	}
	solve(0);
	SORT(Ans);
	FOR(i,SZ(Ans)){
		printf(Ans[i].se?"YES\n":"NO\n");
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 13896 KB Output is correct
2 Correct 0 ms 13896 KB Output is correct
3 Correct 0 ms 13896 KB Output is correct
4 Correct 3 ms 13896 KB Output is correct
5 Correct 0 ms 13896 KB Output is correct
6 Correct 0 ms 13896 KB Output is correct
7 Correct 9 ms 13896 KB Output is correct
8 Correct 0 ms 13896 KB Output is correct
9 Correct 3 ms 13896 KB Output is correct
10 Correct 0 ms 13896 KB Output is correct
11 Correct 0 ms 13896 KB Output is correct
12 Correct 3 ms 13896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14028 KB Output is correct
2 Correct 6 ms 14028 KB Output is correct
3 Correct 9 ms 14028 KB Output is correct
4 Correct 9 ms 14028 KB Output is correct
5 Correct 216 ms 14244 KB Output is correct
6 Correct 203 ms 14240 KB Output is correct
7 Correct 113 ms 14176 KB Output is correct
8 Correct 123 ms 14180 KB Output is correct
9 Correct 9 ms 14028 KB Output is correct
10 Correct 6 ms 14028 KB Output is correct
11 Correct 3 ms 14028 KB Output is correct
12 Correct 129 ms 14244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 13896 KB Output is correct
2 Correct 0 ms 13896 KB Output is correct
3 Correct 0 ms 13896 KB Output is correct
4 Correct 3 ms 13896 KB Output is correct
5 Correct 0 ms 13896 KB Output is correct
6 Correct 0 ms 13896 KB Output is correct
7 Correct 9 ms 13896 KB Output is correct
8 Correct 0 ms 13896 KB Output is correct
9 Correct 3 ms 13896 KB Output is correct
10 Correct 0 ms 13896 KB Output is correct
11 Correct 0 ms 13896 KB Output is correct
12 Correct 3 ms 13896 KB Output is correct
13 Correct 9 ms 14028 KB Output is correct
14 Correct 6 ms 14028 KB Output is correct
15 Correct 9 ms 14028 KB Output is correct
16 Correct 9 ms 14028 KB Output is correct
17 Correct 216 ms 14244 KB Output is correct
18 Correct 203 ms 14240 KB Output is correct
19 Correct 113 ms 14176 KB Output is correct
20 Correct 123 ms 14180 KB Output is correct
21 Correct 9 ms 14028 KB Output is correct
22 Correct 6 ms 14028 KB Output is correct
23 Correct 3 ms 14028 KB Output is correct
24 Correct 129 ms 14244 KB Output is correct
25 Correct 3 ms 14028 KB Output is correct
26 Correct 6 ms 14028 KB Output is correct
27 Correct 3 ms 14028 KB Output is correct
28 Correct 6 ms 14028 KB Output is correct
29 Correct 186 ms 14248 KB Output is correct
30 Correct 196 ms 14240 KB Output is correct
31 Correct 119 ms 14160 KB Output is correct
32 Correct 109 ms 14160 KB Output is correct
33 Correct 6 ms 14028 KB Output is correct
34 Correct 6 ms 14028 KB Output is correct
35 Correct 3 ms 14168 KB Output is correct
36 Correct 173 ms 14280 KB Output is correct