답안 #278058

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
278058 2020-08-21T09:26:54 Z AKaan37 Magic Tree (CEOI19_magictree) C++17
48 / 100
143 ms 33900 KB
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long lo;
typedef pair< lo,lo > PII;
 
#define fi first
#define se second
#define int long long
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
 
const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 100005;
const lo mod = 1000000007;
 
int n,m,b[li],a[li],k,flag,t,dp[li][25],tree[li*4],cevap;
int cev;
string s;
PII p[li];
vector<int> v[li];
vector<PII> vec;
 
inline void dfs(int node,int ata){
	for(int i=0;i<(int)v[node].size();i++){
		int go=v[node][i];
		if(go==ata)continue;
		dfs(go,node);
	}
	
	if(p[node].fi!=0){
		for(int i=p[node].fi;i<=p[node].fi;i++){
			dp[node][i]=max(dp[node][i],(dp[node][p[node].fi]+p[node].se));
		}
	}
	for(int i=1;i<=k;i++)dp[node][i]=max(dp[node][i],dp[node][i-1]);
	//~ cout
	for(int i=1;i<=k;i++){
		dp[ata][i]+=(dp[node][i]);
	}
}

inline void update(int node,int start,int end,int l,int r,int val){
	if(start>end || start>r || end<l)return ;
	if(start>=l && end<=r){tree[node]+=val;return ;}
	update(node*2,start,mid,l,r,val),update(node*2+1,mid+1,end,l,r,val);
	tree[node]=tree[node*2]+tree[node*2+1];
}

inline int query(int node,int start,int end,int l,int r){
	if(start>end || start>r || end<l)return 0;
	if(start>=l && end<=r)return tree[node];
	return query(node*2,start,mid,l,r)+query(node*2+1,mid+1,end,l,r);
}
 
inline void solve(int node,int ata){
	for(int i=0;i<(int)v[node].size();i++){
		int go=v[node][i];
		if(go==ata)continue;
		solve(go,node);
	}
	if(p[node].fi!=0){
		update(1,1,n,p[node].fi,p[node].fi,p[node].se);
		cevap=max(cevap,query(1,1,n,1,p[node].fi));
	}
}

inline void LIS(){
	int len=1;
	b[len]=a[1];
	for(int i=2;i<=m;i++){
		if(a[i]<b[1])b[1]=a[i];
		else if(a[i]>=b[len])b[++len]=a[i];
		else{
			int bas=1;
			int son=len;
			while(bas<=son){
				if(b[ort]>a[i])son=ort-1;
				else bas=ort+1;
			}
			b[bas]=a[i];
		}
	}
	printf("%lld\n",len);exit(0);
}

main(void){
	scanf("%lld %lld %lld",&n,&m,&k);
	int yes=0,yes1=0;
	for(int i=2;i<=n;i++){
		int x;
		scanf("%lld",&x);
		v[i].pb(x);
		v[x].pb(i);
		if(x==i-1)yes++;
	}
	for(int i=1;i<=m;i++){
		int x,y,z;
		scanf("%lld %lld %lld",&x,&y,&z);
		if(z==1)yes1++;
		cev+=z;
		p[x].fi=y;
		p[x].se=z;
		vec.pb({x,y});
	}
	if(k<=20){
		cev=0;
		dfs(1,0);
		for(int i=1;i<=k;i++)cev=max(cev,dp[i][k]);
	}
	if(yes==n-1 && yes1==m){
		sort(vec.begin(),vec.end());
		reverse(vec.begin(),vec.end());
		for(int i=0;i<m;i++)a[i+1]=vec[i].se;
		LIS();
	}
	printf("%lld\n",cev);
	return 0;
}

Compilation message

magictree.cpp:100:10: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  100 | main(void){
      |          ^
magictree.cpp: In function 'int main()':
magictree.cpp:101:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  101 |  scanf("%lld %lld %lld",&n,&m,&k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:105:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  105 |   scanf("%lld",&x);
      |   ~~~~~^~~~~~~~~~~
magictree.cpp:112:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  112 |   scanf("%lld %lld %lld",&x,&y,&z);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 3 ms 2688 KB Output is correct
4 Correct 3 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2664 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 8564 KB Output is correct
2 Correct 43 ms 7032 KB Output is correct
3 Correct 85 ms 10224 KB Output is correct
4 Correct 79 ms 10344 KB Output is correct
5 Correct 80 ms 10224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Correct 62 ms 9836 KB Output is correct
5 Correct 64 ms 10636 KB Output is correct
6 Correct 73 ms 9832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 29028 KB Output is correct
2 Correct 143 ms 29028 KB Output is correct
3 Correct 92 ms 30572 KB Output is correct
4 Correct 111 ms 29280 KB Output is correct
5 Correct 88 ms 33204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 3 ms 2688 KB Output is correct
4 Correct 3 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2664 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 115 ms 29028 KB Output is correct
11 Correct 107 ms 29028 KB Output is correct
12 Correct 100 ms 30568 KB Output is correct
13 Correct 91 ms 29284 KB Output is correct
14 Correct 81 ms 33900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 3712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 3 ms 2688 KB Output is correct
4 Correct 3 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2664 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 4 ms 2688 KB Output is correct
13 Correct 62 ms 9836 KB Output is correct
14 Correct 64 ms 10636 KB Output is correct
15 Correct 73 ms 9832 KB Output is correct
16 Correct 115 ms 29028 KB Output is correct
17 Correct 107 ms 29028 KB Output is correct
18 Correct 100 ms 30568 KB Output is correct
19 Correct 91 ms 29284 KB Output is correct
20 Correct 81 ms 33900 KB Output is correct
21 Incorrect 14 ms 4348 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 3 ms 2688 KB Output is correct
4 Correct 3 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2664 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 55 ms 8564 KB Output is correct
11 Correct 43 ms 7032 KB Output is correct
12 Correct 85 ms 10224 KB Output is correct
13 Correct 79 ms 10344 KB Output is correct
14 Correct 80 ms 10224 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 2 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 62 ms 9836 KB Output is correct
19 Correct 64 ms 10636 KB Output is correct
20 Correct 73 ms 9832 KB Output is correct
21 Correct 136 ms 29028 KB Output is correct
22 Correct 143 ms 29028 KB Output is correct
23 Correct 92 ms 30572 KB Output is correct
24 Correct 111 ms 29280 KB Output is correct
25 Correct 88 ms 33204 KB Output is correct
26 Correct 115 ms 29028 KB Output is correct
27 Correct 107 ms 29028 KB Output is correct
28 Correct 100 ms 30568 KB Output is correct
29 Correct 91 ms 29284 KB Output is correct
30 Correct 81 ms 33900 KB Output is correct
31 Incorrect 8 ms 3712 KB Output isn't correct
32 Halted 0 ms 0 KB -