D
赛时感觉递归会超时,实际上根据主定理算一下并不会。
#include<bits/stdc++.h>
#define endl '\n'
#define pii pair<int,int>
using namespace std;
using ll = long long;
int n,m;
bool f(int n)
{
if(n==m) return true;
if(n==0||n%3!=0) return false;
else
{
return f(n/3*2)|f(n/3);
}
}
void solve()
{
cin>>n>>m;
if(n==m) {cout<<"YES"<<endl; return ;}
if(n%3||m>n) {cout<<"NO"<<endl; return ;}
if(f(n)) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T; cin>>T;
while(T--)
solve();
return 0;
}
F
根据题意可以看出,所有节点的出度最多有三种情况,最多的那种显然是最外层的点,如果有三种出度情况,
y
y
y 就是最多的那种情况除以第二多的,即中间那层的节点数量,如果只有两种,说明最里面的和中间的节点出度恰好相同,只需要对第二多的数量减一即可。
#include<bits/stdc++.h>
#define endl '\n'
#define pii pair<int,int>
using namespace std;
using ll = long long;
const int maxn = 203;
int a[maxn];
map<int,int> mp;
bool cmp(int x,int y)
{
return x>y;
}
void solve()
{
mp.clear();
memset(a,0,sizeof(a));
int n,m;
cin>>n>>m;
int u,v;
for(int i=1;i<=m;i++)
{
cin>>u>>v;
a[u]++,a[v]++;
}
for(int i=1;i<=n;i++) // 有 a[i] 条边的点有 mp[a[i]] 个
if(a[i]) mp[a[i]]++;
vector<int> cnt;
for(auto x:mp)
{
cnt.push_back(x.second);
}
sort(cnt.begin(),cnt.end());
if (cnt.size() == 3) {
cout << cnt[1] << ' ' << cnt[2] / cnt[1] << endl;
}
else {
cout << cnt[0] - 1 << ' ' << cnt[1] / (cnt[0] - 1) << endl;
}
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T; cin>>T;
while(T--)
solve();
return 0;
}