| Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|---|
| 41398 | stevenyu | 【S】T2 | C++ | 运行超时 | 40 | 1000 MS | 776 KB | 1452 | 2026-04-22 18:33:35 |
#include<bits/stdc++.h> using namespace std; int n,k; int fa[100005]; queue<pair<int,int>>ans; deque<pair<int,int>>q; int find(int nw){ if(fa[nw]==nw)return nw; return find(fa[nw]); } void dfs(int st){ if(!ans.empty()){ return; } if(st>(n/2)){ while(!q.empty()){ ans.push(q.front()); q.pop_front(); } cout<<n/2<<endl; while(!ans.empty()){ cout<<ans.front().first<<" "<<ans.front().second<<endl; ans.pop(); } exit(0); } for(int i=0;i<=n-1;i++){ for(int j=0;j<=n-1;j++){ if(i==j)continue; int fi=find(i),fj=find(j); if(fi==fj)continue; int nw1=fa[fi]; fa[fi]=fj; int fi2=find((i+k)%n),fj2=find((j+k)%n); if(fi2==fj2){ fa[fi]=nw1; continue; } int nw2=fa[fi2]; fa[fi]=fj; fa[fi2]=fj2; q.push_back(make_pair(i,j)); dfs(st+1); if(!ans.empty())return; q.pop_back(); fa[fi]=nw1,fa[fi2]=nw2; } } } signed main(){ cin>>n>>k; if(n%2==0){ cout<<-1<<endl; return 0; } for(int i=0;i<=n-1;i++)fa[i]=i; dfs(1); if(ans.empty()){ cout<<-1<<endl; return 0; } return 0; }