当前位置:网站首页>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;
}
};
边栏推荐
- 019 basics of C language: C preprocessing
- Neo4j community conflicts with neo4j desktop
- 双位置继电器RXMVB2 R251 204 110DC
- Edge在IE模式下加载网页 - Edge设置IE兼容性
- How pychart installs packages
- jq怎么获取元素的id名
- Qt使用Valgrind分析内存泄漏
- 010 C语言基础:C函数
- Microservice system design -- Distributed timing service design
- Execution rules of pytest framework
猜你喜欢

【FPGA】基于bt1120时序设计实现棋盘格横纵向灰阶图数据输出
![[nips 2017] pointnet++: deep feature learning of point set in metric space](/img/3e/0a47eecc27f236d629c611e683b37a.png)
[nips 2017] pointnet++: deep feature learning of point set in metric space
![[station B up dr_can learning notes] Kalman filter 1](/img/18/ee21d31f6a118e4e4ad466b55361cc.gif)
[station B up dr_can learning notes] Kalman filter 1

Avoid asteroids
![[unity] button of UI interactive component & summary of optional base classes](/img/9f/be9005f03ad9a2bc8da0f910f064c5.png)
[unity] button of UI interactive component & summary of optional base classes

Edge loads web pages in IE mode - edge sets ie compatibility

Microservice system design -- API gateway service design

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

leetcode299周赛记录

stm32读取IO高低电平状态
随机推荐
《数据库原理与应用》第一版 马春梅……编著 期末复习笔记
清华大学开源软件镜像站网址
017 basics of C language: bit field and typedef
Ad22 Gerber files Click to open the Gerber step interface. Official solutions to problems
[unity] button of UI interactive component & summary of optional base classes
【NIPS 2017】PointNet++:度量空间中点集的深层次特征学习
Penetration test - file upload / download / include
微服务系统设计——消息缓存服务设计
微服务系统设计——服务熔断和降级设计
Interview: what are the positioning methods in selenium? Which one do you use most?
AD22 gerber files 点开 gerber steup 界面 有问题 官方解决方法
什么是BFC?有什么用?
机械转码日记【17】模板,STL简介
neo4j community与neo4j desktop冲突
unity点光源消失
How pychart installs packages
Microservice system design -- unified authentication service design
Deep dive kotlin synergy (XV): Test kotlin synergy
Chapter 2 Introduction to key technologies
Py2neo basic syntax