Codeforces 1143C

给一棵树,每个节点有一个值,0或1,设当前节点为u ,若u的值为1 并且 所有u的儿子节点的值为1的话,u就可以删除,求删除的节点编号,按从小到大的顺序排列。若不能删除一个输出-1。
一开始想dfs,到叶子节点时输出路径,然而调了半天了没写对。这题的思路在于从反面思考,若当前节点的值为0,则该节点不能被删除,并且其父亲节点(如果有)也不能被删除。

#include<bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i = 0;i<int(n);i++)
typedef long long LL;
int n,ch[101010],root,u,x,flag;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
	cin>>n;
	for(int i = 1;i<=n;i++){
		cin>>u >> x;
		if(!x) {
			ch[i] = 1;
			if(u != -1) ch[u] = 1;
		}
	}
	for(int i = 1;i<=n;i++)	if(!ch[i]){
		flag = 1; cout<<i<<' ';
	}
	if(!flag) cout<<-1;
	return 0; 
} 
### Codeforces 2045C Saraga Problem Explanation The provided references do not contain information regarding the specific problem "Saraga" with ID 2045C from Codeforces. However, based on common practices for solving problems on platforms like Codeforces, a structured approach to understanding and potentially solving this problem involves several key steps. #### Understanding the Problem Statement To effectively tackle any competitive programming challenge, comprehending the exact requirements as outlined in the official problem statement is crucial. For an unspecified problem such as "Saraga," one should start by carefully reading through all sections including constraints, inputs, outputs, examples, and notes available directly from the source at [Codeforces](https://codeforces.com/) under contest number 2045, problem C[^1]. #### Analyzing Constraints Typically, analyzing given limits helps determine which algorithms might fit within those boundaries efficiently. Problems often specify maximum values for variables used in calculations or array sizes that influence algorithm choice significantly. #### Identifying Patterns Through Examples Examining sample cases usually provides insights into how solutions behave across different scenarios. This step aids immensely when formulating hypotheses about underlying patterns or properties exploited during implementation. #### Formulating Hypotheses Based on Similarities With Known Concepts Given no direct reference material exists specifically addressing "Saraga," drawing parallels between its description—if accessible—and other well-documented topics could offer valuable clues towards crafting effective strategies. Bitwise operations have been mentioned extensively throughout previous discussions; therefore, considering their applicability remains reasonable depending upon actual task specifications[^5]. ```cpp // Example pseudo-code structure without concrete logic due to lack of detailed problem definition. #include <bits/stdc++.h> using namespace std; int main() { // Placeholder code block illustrating general setup rather than precise functionality related to 'Saraga'. } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值