「杂题乱刷2」CF827B
1.「杂题乱刷」CF1904B2.「杂题乱刷」CF1620E3.「杂题乱刷」CF978G4.「杂题乱刷」洛谷P92535.「杂题乱刷」CF624B6.「杂题乱刷」CF1221B7.「杂题乱刷」CF1585B8.「杂题乱刷」CF468A9.「杂题乱刷」洛谷P951510.「杂题乱刷」CF283A11.「杂题乱刷」洛谷P953312.「杂题乱刷」CF1914E1 & CF1914E213.「杂题乱刷」AT_abc280_d14.「杂题乱刷」CF1916C15.「杂题乱刷」AT_arc041_b16.【待补题解】AT_arc146_a17.「杂题乱刷」AT_abc337_e18.「杂题乱刷」AT_abc308_f19.「杂题乱刷」ZhengRui 54. 【17 普及 13】幻想嘉年华20.「杂题乱刷」CF1925C & CF1924A21.「杂题乱刷」CF1927D22.「杂题乱刷」洛谷 P1015523.「杂题乱刷」洛谷 P171224.「杂题乱刷」洛谷 P886625.「杂题乱刷」CF1937C & CF1936A26.「杂题乱刷」CF1934D227.「杂题乱刷」洛谷 P480128.「杂题乱刷」ZhengRui 611 【19寒假普转提】树的权29.「杂题乱刷」ZhengRui 281 汪初雪与高流星30.「杂题乱刷」at_abc092_d & AT_arc093_b31.「杂题乱刷」CF74E32.「杂题乱刷」AT_abc279_e33.「杂题乱刷」AT_abc096_d34.「杂题乱刷」CF1973D35.「杂题乱刷」CF1650D36.「杂题乱刷」CF1650E37.「杂题乱刷」CF1977B38.「杂题乱刷」CF1977C39.「杂题乱刷」CF460C40.「杂题乱刷」P827941.「杂题乱刷」AT_abc160_e42.「杂题乱刷」P1051243.「杂题乱刷」AT_abc358_g44.「杂题乱刷」 AT_abc123_d45.「杂题乱刷」P7840 & AT_abc359_f46.「杂题乱刷」CF1987C47.「杂题乱刷」P1067848.「杂题乱刷2」CF1702F49.「杂题乱刷2」CF402D Upgrading Array50.「杂题乱刷2」CF1506E Restoring the Permutation51.「杂题乱刷2」CF727D52.「杂题乱刷2」CF1615C Menorah53.「杂题乱刷2」CF1889A Qingshan Loves Strings 254.「杂题乱刷2」CF1527B255.「杂题乱刷2」CF1108E2
56.「杂题乱刷2」CF827B
57.「杂题乱刷2」CF1227D258.「杂题乱刷2」CF2066B题目链接
解题思路
假设树以
时间复杂度
参考代码
点击查看代码
#include<bits/stdc++.h>
using namespace std;
//#define map unordered_map
#define re register
#define ll long long
#define forl(i,a,b) for(re ll i=a;i<=b;i++)
#define forr(i,a,b) for(re ll i=a;i>=b;i--)
#define forll(i,a,b,c) for(re ll i=a;i<=b;i+=c)
#define forrr(i,a,b,c) for(re ll i=a;i>=b;i-=c)
#define pii pair<ll,ll>
#define mid ((l+r)>>1)
#define lowbit(x) (x&-x)
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl '\n'
#define QwQ return 0;
#define db long double
#define ull unsigned long long
#define lcm(x,y) (1ll*(x)/__gcd(x,y)*(y))
#define Sum(x,y) (1ll*((x)+(y))*((y)-(x)+1)/2)
#define x first
#define y second
#define aty cout<<"Yes\n";
#define atn cout<<"No\n";
#define cfy cout<<"YES\n";
#define cfn cout<<"NO\n";
#define xxy cout<<"yes\n";
#define xxn cout<<"no\n";
#define printcf(x) x?cout<<"YES\n":cout<<"NO\n";
#define printat(x) x?cout<<"Yes\n":cout<<"No\n";
#define printxx(x) x?cout<<"yes\n":cout<<"no\n";
#define maxqueue priority_queue<ll>
#define minqueue priority_queue<pii,vector<pii>,greater<pii>>
#define bug cout<<"---------------------------------------\n";
//ll pw(ll x,ll y,ll mod){if(y==0)return 1;if(x==0)return 0;ll an=1,tmp=x;while(y){if(y&1)an=(an*tmp)%mod;tmp=(tmp*tmp)%mod;y>>=1;}return an;}
template<typename T1,typename T2>bool Max(T1&x,T2 y){if(y>x)return x=y,1;return 0;}
template<typename T1,typename T2>bool Min(T1&x,T2 y){if(y<x)return x=y,1;return 0;}
ll _t_;
void _clear(){}
ll n,m;
minqueue q;
vector<pii>ans;
ll a[200010];
ll k;
void solve()
{
_clear();
cin>>n>>m;
if(m==2)
{
cout<<n-1<<endl;
forl(i,1,n-1)
cout<<i<<' '<<i+1<<endl;
return ;
}
forl(i,2,m+1)
q.push({1,i}),ans.pb({1,i}),a[++k]=1;
forl(i,m+2,n)
{
pii now=q.top();
q.pop();
ans.pb({now.y,i});
a[++k]=now.x+1;
q.push({now.x+1,i});
}
sort(a+1,a+1+k);
cout<<a[k]+a[k-1]<<endl;
for(auto i:ans)
cout<<i.x<<' '<<i.y<<endl;
}
int main()
{
// freopen("tst.txt","r",stdin);
// freopen("sans.txt","w",stdout);
IOS;
_t_=1;
// cin>>_t_;
while(_t_--)
solve();
QwQ;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效