Teacher YY(13594088355)
爆搜AC踩标程,掌声送给剪枝人
十年OI一场空,不开long long见祖宗
数学先打表,D P 看运气
穷举TLE,递推UKE
模拟MLE,贪心还CE
图论背模板,数论背公式
动规背方程,高精背代码
骗分过样例,暴力出奇迹
爆搜挂着机,打表出省一
P8423[THUPC2022 决赛] 想象
代码草稿区
#include <bits/stdc++.h>
using namespace std;
vector <int> g[10010];
int d[10010],sum[10010],a[10010];
int f[10010][10010];
void dfs(int x, int y){
d[x]=d[y]+1;
f[x][0]=y;
for(int i=1;(1<<i)<=d[x];i++)
f[x][i]=f[f[x][i-1]][i-1];
for(int i=0;i<g[x].size();i++){
if(g[x][i]==y) continue;
sum[g[x][i]]=sum[x]+a[g[x][i]];
dfs(g[x][i],x);
}
}
int lca(int x,int y){
if(d[x]<d[y]) swap(x,y);
for(int j=19;j>=0;j--) if(d[f[x][j]]>=d[y]) x=f[x][j];
if(x==y) return x;
for(int j=19;j>=0;j--){
if(f[x][j]!=f[y][j]){
x=f[x][j];
y=f[y][j];
}
}
return f[x][0];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);//快读
int n,m,s;
cin>>n>>m>>s;
for (int i=1,x,y;i<n;i++) {
cin>>x>>y;
g[x].push_back(y);
g[y].push_back(x);
}//邻接表
dfs(s,0);
for(int j=1;j<20;j++)
for(int i=1;i<=n;i++)
f[i][j]=f[f[i][j-1]][j-1];//倍增
while(m--){
int a,b;
cin>>a>>b;
cout<<lca(a,b)<<endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int n,m,cnt,ans;
int head[10010];
struct edge{
int nex,v;
}d[200010];
void add(int u,int v){
cnt++;
d[cnt].v=v;
d[cnt].nex=head[u];
head[u]=cnt;
}
int main(){
return 0;
}快读
ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);- 定义队列如下:
- queue<int> q;
- priority_queue <int,vector<int>,greater<int> > q;
- q.empty(); //队空返true ,否则返false;
- q.size(); //返回队中元素个数
- q.pop();//删除队列首元素但不返回
- q.front();//返回队列首元素的值且不删除
- q.back();//返回队列尾元素的值且不删除
- q.push();//在队尾压入新元素
剪贴板
- Sumup
- 关系网 -https://chat.deepseek.com/a/chat/s/51fa7cc8-6c73-4aeb-9c6f-04addbec8890
- https://www.msn.cn/zh-cn/news/other/%E5%A4%9A%E9%82%BB%E5%9B%BD-%E8%BF%BD%E5%91%BD%E5%B0%8F%E7%BB%BF%E9%B8%9F-%E5%8E%BB%E4%B8%96-%E7%BD%91%E5%8F%8B%E5%96%9C%E5%A4%A7%E6%99%AE%E5%A5%94-%E7%BB%88%E4%BA%8E-%E4%B8%8D%E7%94%A8-%E5%AD%A6%E5%A4%96%E8%AF%AD%E4%BA%86/ar-AA1z2gkA?ocid=msedgdhp&pc=U531&cvid=67af4573bb43429a8656327a93d76ea0&ei=10
- 学术网站https://cn.bing.com/academic