답안 #278020

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
278020 2020-08-21T08:53:28 Z AKaan37 Magic Tree (CEOI19_magictree) C++17
37 / 100
132 ms 31736 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 = 1003;
const lo mod = 1000000007;

int n,m,k,flag,t,dp[100002][25],dp1[li][100002];
int cev;
string s;
PII p[100002];
vector<int> v[100002];

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 dfs1(int node,int ata){
	for(int i=0;i<(int)v[node].size();i++){
		int go=v[node][i];
		if(go==ata)continue;
		dfs1(go,node);
	}
	
	if(p[node].fi!=0){
		for(int i=p[node].fi;i<=p[node].fi;i++){
			dp1[node][i]=max(dp1[node][i],(dp1[node][p[node].fi]+p[node].se));
		}
	}
	for(int i=1;i<=k;i++)dp1[node][i]=max(dp1[node][i],dp1[node][i-1]);
	//~ cout
	for(int i=1;i<=k;i++){
		dp1[ata][i]+=(dp1[node][i]);
	}
}

main(void){
	scanf("%lld %lld %lld",&n,&m,&k);
	for(int i=2;i<=n;i++){
		int x;
		scanf("%lld",&x);
		v[i].pb(x);
		v[x].pb(i);
	}
	for(int i=1;i<=m;i++){
		int x,y,z;
		scanf("%lld %lld %lld",&x,&y,&z);
		cev+=z;
		p[x].fi=y;
		p[x].se=z;
	}
	if(k<=20){
		cev=0;
		dfs(1,0);
		for(int i=1;i<=k;i++)cev=max(cev,dp[i][k]);
	}
	if(n<=1001){
		cev=0;
		dfs1(1,0);
		for(int i=1;i<=k;i++)cev=max(cev,dp1[i][k]);
	}
	printf("%lld\n",cev);
	return 0;
}

Compilation message

magictree.cpp:74:10: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   74 | main(void){
      |          ^
magictree.cpp: In function 'int main()':
magictree.cpp:75:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   75 |  scanf("%lld %lld %lld",&n,&m,&k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:78:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   78 |   scanf("%lld",&x);
      |   ~~~~~^~~~~~~~~~~
magictree.cpp:84:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   84 |   scanf("%lld %lld %lld",&x,&y,&z);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2816 KB Output is correct
3 Correct 2 ms 2816 KB Output is correct
4 Correct 2 ms 2816 KB Output is correct
5 Correct 2 ms 2816 KB Output is correct
6 Correct 2 ms 2816 KB Output is correct
7 Correct 2 ms 2816 KB Output is correct
8 Correct 2 ms 2816 KB Output is correct
9 Correct 2 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 8056 KB Output is correct
2 Correct 40 ms 6392 KB Output is correct
3 Correct 86 ms 8440 KB Output is correct
4 Correct 63 ms 8128 KB Output is correct
5 Correct 74 ms 8440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 16256 KB Output is correct
2 Correct 16 ms 16128 KB Output is correct
3 Correct 14 ms 16128 KB Output is correct
4 Incorrect 60 ms 9232 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 27596 KB Output is correct
2 Correct 132 ms 27512 KB Output is correct
3 Correct 110 ms 29132 KB Output is correct
4 Correct 78 ms 27756 KB Output is correct
5 Correct 88 ms 31676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2816 KB Output is correct
3 Correct 2 ms 2816 KB Output is correct
4 Correct 2 ms 2816 KB Output is correct
5 Correct 2 ms 2816 KB Output is correct
6 Correct 2 ms 2816 KB Output is correct
7 Correct 2 ms 2816 KB Output is correct
8 Correct 2 ms 2816 KB Output is correct
9 Correct 2 ms 2816 KB Output is correct
10 Correct 118 ms 27512 KB Output is correct
11 Correct 105 ms 27512 KB Output is correct
12 Correct 113 ms 29176 KB Output is correct
13 Correct 73 ms 27756 KB Output is correct
14 Correct 85 ms 31736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 3712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2816 KB Output is correct
3 Correct 2 ms 2816 KB Output is correct
4 Correct 2 ms 2816 KB Output is correct
5 Correct 2 ms 2816 KB Output is correct
6 Correct 2 ms 2816 KB Output is correct
7 Correct 2 ms 2816 KB Output is correct
8 Correct 2 ms 2816 KB Output is correct
9 Correct 2 ms 2816 KB Output is correct
10 Correct 14 ms 16256 KB Output is correct
11 Correct 16 ms 16128 KB Output is correct
12 Correct 14 ms 16128 KB Output is correct
13 Incorrect 60 ms 9232 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2816 KB Output is correct
3 Correct 2 ms 2816 KB Output is correct
4 Correct 2 ms 2816 KB Output is correct
5 Correct 2 ms 2816 KB Output is correct
6 Correct 2 ms 2816 KB Output is correct
7 Correct 2 ms 2816 KB Output is correct
8 Correct 2 ms 2816 KB Output is correct
9 Correct 2 ms 2816 KB Output is correct
10 Correct 48 ms 8056 KB Output is correct
11 Correct 40 ms 6392 KB Output is correct
12 Correct 86 ms 8440 KB Output is correct
13 Correct 63 ms 8128 KB Output is correct
14 Correct 74 ms 8440 KB Output is correct
15 Correct 14 ms 16256 KB Output is correct
16 Correct 16 ms 16128 KB Output is correct
17 Correct 14 ms 16128 KB Output is correct
18 Incorrect 60 ms 9232 KB Output isn't correct
19 Halted 0 ms 0 KB -