답안 #1107603

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107603 2024-11-01T16:55:30 Z vjudge1 Magic Tree (CEOI19_magictree) C++17
0 / 100
2 ms 592 KB
/******************************************************
| '_ \ / _` |/ __| '_ ` _ \ / _` | '_ \
| |_) | (_| | (__| | | | | | (_| | | | |
| .__/ \__,_|\___|_| |_| |_|\__,_|_| |_|
|_|

__|      |____________________________________________
     ,--.    ,--.          ,--.   ,--.
    |oo  | _  \  `.       | oo | |  oo|
o  o|~~  |(_) /   ;       | ~~ | |  ~~|o  o  o  o  o
    |/\/\|   '._,'        |/\/\| |/\/\|
__________________        ____________________________
******************************************************/

#include <bits/stdc++.h>
//#include "bigint.h"
#define db(x) cerr << #x << ": " << x << endl
#define print cerr << "Ah shit, here we go agian" << endl
#define int long long int
#define vii vector<int>
#define pii pair<int ,int>
#define vpi vector< pii >
#define ff first
#define ss second
#define mp make_pair
#define mod 1000000007

using namespace std;

const int maxn = 100;

int n, m ,k;

struct mive{
	int v ,d ,w;
};

int st[maxn], fn[maxn], timer = 1;

vector<int> adj[maxn];
vector<mive> f;

void dfs(int v,int mpar = 0){
	st[v] = timer++;
	for(auto u : adj[v]){
		if(u != mpar){
			dfs(u ,v);
		}
	}
	fn[v] = timer++;
}

bool zird(int u ,int v){
	return st[u] >= st[v] and fn[u] <= fn[v];
}



void solve(){
	cin >> n >> m >> k;
	for(int i = 2 ;i <= n; i++){
		int x;
		cin >> x;
		adj[x].push_back(i);
		adj[i].push_back(x);
	}
	
	for(int i = 0 ;i < m ; i++){
		int x, y ,z;
		cin >> x >> y >> z;
		f.push_back({x ,y ,z});
	}
	
	dfs(1);
	
	vector<int> v(m , 0);
	
	for(int i = 0 ; i < m ; i++){
		for(int j = 0; j< m ;j ++){
			if(i != j and zird(f[j].v, f[i].v) and f[j].d <= f[i].d){
				v[i] |= (1 << j);
			}
		}
	}
	
	int ans = 0;
	for(int mask = 0 ; mask < (1 << m); mask++){
		bool f = true;
		for(int i = 0 ;i < m and f ; i++){
			if(v[i] & mask){
				f = false;
			}
		}
		if(f){
			ans = max(ans , (int)__builtin_popcount(mask));
		}
	}
	
	cout << ans << endl;
}


signed main(){

	ios_base::sync_with_stdio(0), cin.tie(0) ,cout.tie(0);

	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	int t = 1;
///	cin >> t;
	while(t--){
		solve();
	}

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 592 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 592 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 592 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -