HDU5156(离线tarjan+打标记)

Harry and Christmas tree

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 213    Accepted Submission(s): 53


Problem Description
In Christmas Day, Harry got a Christmas tree. The tree has n nodes. And you can assume the tree rooted at node 1. Harry found that there are some gifts with different colors on some nodes. Then Harry began to count the gifts on the tree. Every time Harrty counted a gift, he written down a pair (a, b) on the paper. Where a indecates which node this gift located, and b indecates the color of this gift. After Harry finished all his counting, for each node x, he wanted to know the number of different kinds of colors that all gifts located on the subtree rooted at node x had.
 

Input
There are several test cases,you should process to the end of file.
For each test case, there are two integers n m on the first line, n indecates the number of the nodes, m indecates the number of countings.  1n50000,1m500000
The next following n-1 lines. Each line contains two integers a b, it means there is an edge between a and b.  1a,bn,ab .
The next following m lines. Each line contains two integers a b, indecates the countings.  1an,1b100000 .
 

Output
For each test case output one line contains n numbers, where a[i] indecates the number of different kinds of colors that all gifts located on the subtree rooted at node i had.
 

Sample Input
   
5 3 3 1 4 1 2 3 5 1 1 9 4 6 4 6
 

Sample Output
   
2 0 0 1 0
Hint
Make your program running as fast as possible.
 

Source
 

Recommend
heyang   |   We have carefully selected several similar problems for you:   5157  5154  5153  5152  5151 

题意:RT

思路:大概就是打标记,每个点u对从u到树根1上的路径上点贡献为1,在u上+1就好了,这样如果u和v的颜色一样,

            那么就会对u和v的最近公共祖先f到树根1上的路径上的点算重复一次,所以只需在f上-1就好了

            唯一的坑点是,求最近公共祖先要用离线Tarjan来求,我的这种写法还要加输入挂,否则照样T = =

#pragma comment(linker,"/STACK:102400000,102400000")
#include 
  
   
#include 
   
    
#include 
    
     
#include 
     
      
#include 
      
       
#include 
       
         using namespace std; const int MAXN = 50005; vector
        
          b[MAXN<<1]; vector
         
           a[MAXN]; int head[MAXN]; int edge[MAXN<<1]; int next[MAXN<<1]; int esz; int ans[MAXN]; int n,m; int head1[MAXN]; int edge1[500005]; int next1[500005]; int esz1; int Fa[MAXN]; int vis[MAXN]; void init() { for(int i=1;i<=n;i++){ vis[i]=0; Fa[i]=i; head1[i]=head[i]=-1; ans[i]=0; } esz=esz1=0; } void addedge(int u,int v) { edge[esz]=v; next[esz]=head[u]; head[u]=esz++; } void dfs(int u,int p) { int L=a[u].size(); for(int i=0;i
          
           0)a[i].clear(); for(int i=1;i
           
          
         
        
       
      
     
    
   
  
内容概要:该研究通过在黑龙江省某示范村进行24小时实地测试,比较了燃煤炉具与自动/手动进料生物质炉具的污染物排放特征。结果显示,生物质炉具相比燃煤炉具显著降低了PM2.5、CO和SO2的排放(自动进料分别降低41.2%、54.3%、40.0%;手动进料降低35.3%、22.1%、20.0%),但NOx排放未降低甚至有所增加。研究还发现,经济性和便利性是影响生物质炉具推广的重要因素。该研究不仅提供了实际排放数据支持,还通过Python代码详细复现了排放特征比较、减排效果计算和结果可视化,进一步探讨了燃料性质、动态排放特征、碳平衡计算以及政策建议。 适合人群:从事环境科学研究的学者、政府环保部门工作人员、能源政策制定者、关注农村能源转型的社会人士。 使用场景及目标:①评估生物质炉具在农村地区的推广潜力;②为政策制定者提供科学依据,优化补贴政策;③帮助研究人员深入了解生物质炉具的排放特征和技术改进方向;④为企业研发更高效的生物质炉具提供参考。 其他说明:该研究通过大量数据分析和模拟,揭示了生物质炉具在实际应用中的优点和挑战,特别是NOx排放增加的问题。研究还提出了多项具体的技术改进方向和政策建议,如优化进料方式、提高热效率、建设本地颗粒厂等,为生物质炉具的广泛推广提供了可行路径。此外,研究还开发了一个智能政策建议生成系统,可以根据不同地区的特征定制化生成政策建议,为农村能源转型提供了有力支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值