http://acm.timus.ru/problem.aspx?space=1&num=1630
俄罗斯人的英语 你伤不起呀 看了N久也没看懂什么意思 最后查了N久 然后查了一份题解
关键在于这句话 “ then the minimal number of rods in a chain connecting these balls must be equal
to the distance in centimeters between the centers of the balls”
其实就是 两个球的最短连接 rod 数量必须等于这两个球的距离 反过来就好理解了 这两个球的距离等于 连接他们最短的那条链 的rod 数量
如果连接他们的最少的一条链 有k个rods 那么它们之间的距离就必须是 k
对于第二个样例 4 和 2 之间最少有两个rods 4和3之间也最少有两个rods 但是 4在和1 距离为1cm的情况下 无法同时和2 ,3的距离都是2cm
对于一个联通量 符合条件有两种情况
1,是一条长链
2,球的数量小于等于4 且是全图
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#define LL long long
#define sint short int
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int N=105;
const int INF=0x3f3f3f3f;
vector<int>vt[N];
vector<int>tmp;
bool visited[N];
void dfs(int x)
{
visited[x]=true;
tmp.push_back(x);
for(unsigned int i=0;i<vt[x].size();++i)
{
if(!visited[vt[x][i]])
dfs(vt[x][i]);
}
}
int main()
{
//freopen("data.in","r",stdin);
int n,m;
cin>>n>>m;
while(m--)
{
int l,r;
cin>>l>>r;
vt[l].push_back(r);
vt[r].push_back(l);
}
memset(visited,false,sizeof(visited));
for(int i=1;i<=n;++i)
if(!visited[i])
{
tmp.clear();
dfs(i);
int sum=0;
int M1=0,M2=0;
int m=tmp.size();
for(int i=0;i<m;++i)
{
int k=tmp[i];
sum+=vt[k].size();
if(vt[k].size()==2)
++M2;
if(vt[k].size()==1)
++M1;
}
if(M1==2&&M1+M2==m)
continue;
if(m<=4&&m*(m-1)==sum)
continue;
cout<<"Unlucky Petr"<<endl;
return 0;
}
cout<<"Luck is possible"<<endl;
return 0;
}