当前位置:网站首页>Leetcode99 week race record
Leetcode99 week race record
2022-06-27 05:17:00 【nth2000】
Remove the minimum fraction of edges from the tree 


Ideas
- Enumerate every 2 side , And then sort it out : The subtree below one edge deletes the other edge ; Or edges in different subtrees .
- Key points : How to judge the node hierarchy , Parent node and child node information
- Using time stamps : Setting global clock,dfs The time of each stack entry record of the middle node is clock+1, When withdrawing from the stack, record the withdrawal time as clock. Then node y It's a node. x The necessary and sufficient condition for the offspring of :
i n [ x ] ≤ i n [ y ] ≤ o u t [ y ] ≤ o u t [ x ] in[x] \leq in[y] \leq out[y] \leq out[x] in[x]≤in[y]≤out[y]≤out[x]
class Solution {
public:
int clock = 0;
int minimumScore(vector<int>& nums, vector<vector<int>>& edges) {
vector<int> adj[nums.size()];
for(auto& p : edges)
{
adj[p[0]].push_back(p[1]);
adj[p[1]].push_back(p[0]);
}
int c[nums.size()];
for(int i = 0;i<nums.size();i++) {
c[i] = 1001;}
int in[nums.size()];
int out[nums.size()];
function<int(int,int)> dfs = [&](int f,int cur)
{
in[cur] = clock++;
for(int v: adj[cur])
{
if(v!=f)
{
nums[cur] ^= dfs(cur,v);
}
}
out[cur] = clock;
return nums[cur];
};
dfs(-1,0);
// Hierarchy of each point , The hierarchy of leaf nodes is 0
int ans = INT_MAX;
queue<int> d;
c[0] = 1000;
d.push(0);
int cur = 1;
while(!d.empty())
{
int a = d.size();
while(a--)
{
int k = d.front();
c[k]=1000-cur;d.pop();
for(int v : adj[k])
if(c[v]>1000) d.push(v);
}
cur++;
}
for(int i = 0;i<edges.size() - 1;i++)
for(int j = i + 1;j<edges.size();j++)
{
vector<int> up = edges[i];
vector<int> down = edges[j];
if(max(c[edges[i][0]],c[edges[i][1]]) < max(c[edges[j][0]],c[edges[j][1]]))
{
up = edges[j];
down = edges[i];
}
int v = c[up[0]]<c[up[1]]?up[0]:up[1];
int m,n,l;
if(in[down[0]]>=in[v] && out[down[0]] <= out[v])
{
m = c[up[0]]>c[up[1]]?nums[up[1]]:nums[up[0]];
l = nums[0] ^ m;
n = c[down[0]]>c[down[1]]?nums[down[1]]:nums[down[0]];
m = m ^ n;
}
else
{
m = c[up[0]]>c[up[1]]?nums[up[1]]:nums[up[0]];
n = c[down[0]]>c[down[1]]?nums[down[1]]:nums[down[0]];
l = nums[0] ^ m ^ n;
}
ans = min(ans,max(max(m,n),l) - min(min(m,n),l));
}
return ans;
}
};
边栏推荐
- EasyExcel合并相同内容单元格及动态标题功能的实现
- STM32 MCU pin_ How to configure the pin of single chip microcomputer as pull-up input
- AD22 gerber files 点开 gerber steup 界面 有问题 官方解决方法
- 008 C语言基础:C判断
- Interview: what are the positioning methods in selenium? Which one do you use most?
- 齐纳二极管 稳压二极管 SOD123封装 正负区分
- Redis高可用集群(哨兵、集群)
- 体验 win10 下 oceanbase 数据库
- Chapter 2 Introduction to key technologies
- leetcode299周赛记录
猜你喜欢

Avoid asteroids

Terminal in pychar cannot enter the venv environment

微信小程序WebSocket使用案例
![[C language] keyword supplement](/img/c5/171e0d8537d9f09c688e31b290ad65.jpg)
[C language] keyword supplement

【B站UP DR_CAN学习笔记】Kalman滤波2

使用域名转发mqtt协议,避坑指南

Reading graph augmentations to learn graph representations (lg2ar)

Codeforces Round #802 (Div. 2)

Remapping (STM32)
![Mechanical transcoding journal [17] template, STL introduction](/img/78/926db660139fda3d31cceccad7096c.png)
Mechanical transcoding journal [17] template, STL introduction
随机推荐
Deep dive kotlin synergy (XV): Test kotlin synergy
双位置继电器DLS-34A DC0.5A 220VDC
快速排序(非遞歸)和歸並排序
竣达技术丨多品牌精密空调集中监控方案
AD22 gerber files 点开 gerber steup 界面 有问题 官方解决方法
Terminal in pychar cannot enter the venv environment
Unity中跨平台获取系统音量
OpenCV的轮廓检测和阈值处理综合运用
Neo4j community conflicts with neo4j desktop
014 C language foundation: C string
Execution rules of pytest framework
Web3还没实现,Web5乍然惊现!
Edge在IE模式下加载网页 - Edge设置IE兼容性
【B站UP DR_CAN学习笔记】Kalman滤波1
微服务系统设计——分布式定时服务设计
微服务系统设计——统一鉴权服务设计
Almost because of json Stringify lost his bonus
系统架构设计——互联网金融的架构设计
双位置继电器RXMD2-1MRK001984 DC220V
Machunmei, the first edition of principles and applications of database... Compiled final review notes