Zju1015 Fishing Net

  弦图判定

  代码

 #include<cstdio>
#include<queue>
#define mp make_pair
#define fi first
#define sc second
using namespace std;
const int N = ;
int n,m,a,b,i,j;
int dp,p[N],pre[N],tt[N],o,vis[N],sum[N],id[N],ID[N];
priority_queue<pair<int,int> > Q;
void link(int x,int y)
{
dp++;pre[dp]=p[x];p[x]=dp;tt[dp]=y;
}
int main()
{
scanf("%d%d",&n,&m);
for (i=;i<=m;i++)
{
scanf("%d%d",&a,&b);
link(a,b);
link(b,a);
}
for (i=;i<=n;i++)
Q.push(mp(,i));
o=n;
while (!Q.empty())
{
int x=Q.top().fi;
int y=Q.top().sc;
Q.pop();
if (vis[y]) continue;
if (x<sum[y]) continue;
ID[y]=o;
id[o--]=y;
vis[y]=;
i=p[y];
while (i)
{
if (!vis[tt[i]])
{
sum[tt[i]]++;
Q.push(mp(sum[tt[i]],tt[i]));
}
i=pre[i];
}
}
for (i=;i<=n;i++) vis[i]=; for (j=;j<=n;j++)
{
int x=id[j],cnt1=,cnt2=,mi=0x37373737,y=;
i=p[x];
while (i)
{
if (ID[tt[i]]>j)
{
if (ID[tt[i]]<mi) mi=ID[tt[i]],y=tt[i];
vis[tt[i]]=;cnt1++;
}
i=pre[i];
} if (y)
{
i=p[y];
while (i)
{
if (vis[tt[i]]) cnt2++;
i=pre[i];
}
}
if ((cnt1!=cnt2+)&&(y))
{
printf("Imperfect");
return ;
}
i=p[x];
while (i)
{
vis[tt[i]]=;
i=pre[i];
}
}
printf("Perfect");
}
上一篇:Windows应急响应常识


下一篇:oracle竖表转横表字段合并