当前位置:网站首页>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;
}
};
边栏推荐
- [nips 2017] pointnet++: deep feature learning of point set in metric space
- Deep dive kotlin synergy (XV): Test kotlin synergy
- 微服务系统设计——服务链路跟踪设计
- When STM32 turns off PWM output, it is a method to fix IO output at high or low level.
- OpenCV的轮廓检测和阈值处理综合运用
- 网易云音乐params和encSecKey参数生成代码
- 微服务系统设计——分布式事务服务设计
- 009 C语言基础:C循环
- RTP sending PS stream tool (open source)
- 微服务系统设计——微服务调用设计
猜你喜欢

竣达技术丨多品牌精密空调集中监控方案

什么是BFC?有什么用?

流媒体协议初探(MPEG2-TS、RTSP、RTP、RTCP、SDP、RTMP、HLS、HDS、HSS、MPEG-DASH)

认知篇----2022高考志愿该如何填报

Asp.Net Core6 WebSocket 简单案例

LeetCode-515. 在每个树行中找最大值

stm32读取IO高低电平状态
![[622. design cycle queue]](/img/f2/d499ac9ddc50b73f8c83e8b6af2483.png)
[622. design cycle queue]

Tri rapide (non récursif) et tri de fusion

Some articles about component packaging and my experience
随机推荐
006 C language foundation: C storage class
010 C language foundation: C function
Flink生产问题(1.10)
Microservice system design -- distributed cache service design
leetcode299周赛记录
Microservice system design -- distributed lock service design
Unity point light disappears
Unity中跨平台获取系统音量
轨道姿态常用编程缩写
008 C language foundation: C judgment
Mechanical transcoding journal [17] template, STL introduction
How JQ gets the reciprocal elements
019 C语言基础:C预处理
012 C language foundation: C array
017 basics of C language: bit field and typedef
Common programming abbreviations for orbit attitude
AD22 gerber files 点开 gerber steup 界面 有问题 官方解决方法
微服务系统设计——分布式定时服务设计
es6 0622三
Microservice system design -- distributed transaction service design