记录编号 | 33820 | 评测结果 | AAAAAAAAAAAAAAAAAAAA | ||
---|---|---|---|---|---|
题目名称 | 奥术能量环流 | 最终得分 | 100 | ||
用户昵称 | 是否通过 | 通过 | |||
代码语言 | C++ | 运行时间 | 0.041 s | ||
提交时间 | 2011-11-14 21:15:30 | 内存使用 | 0.73 MiB | ||
#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> using namespace std; struct EDGE { int to,fo; }e[40001]; int i,j,n,m,tot,now,x,ans,timee; int l[10001]; bool ins[10001]; int dog,s[10001],tim[10001],low[10001]; void makeside(int x) { int p=x%2; if (p==1 && j%m!=0) {tot++;e[tot].to=now+1;e[tot].fo=l[now];l[now]=tot;} x/=2;p=x%2; if (p==1 && j%m!=1) {tot++;e[tot].to=now-1;e[tot].fo=l[now];l[now]=tot;} x/=2;p=x%2; if (p==1 && i!=n) {tot++;e[tot].to=now+m;e[tot].fo=l[now];l[now]=tot;} x/=2;p=x%2; if (p==1 && i!=1) {tot++;e[tot].to=now-m;e[tot].fo=l[now];l[now]=tot;} } void tarjan(int u) { int j=l[u],o; tim[u]=low[u]=++timee; ins[u]=true; s[++dog]=u; while (j!=0) { o=e[j].to; if (!tim[o]) { tarjan(o); if (low[o]<low[u]) low[u]=low[o]; } else if (ins[o] && tim[o]<low[u]) low[u]=tim[o]; j=e[j].fo; } if (tim[u]==low[u]) { int num=0; do { num++;o=s[dog--];ins[o]=false; }while(o!=u); if (num>1) ans++; } } int main() { freopen("arcane.in","r",stdin); freopen("arcane.out","w",stdout); tot=0; memset(tim,0,sizeof(tim)); scanf("%d %d\n",&n,&m); for (i=1;i<=n;i++) for (j=1;j<=m;j++) { scanf("%d",&x); now=(i-1)*m+j; makeside(x); } dog=0; for (i=1;i<=n*m;i++) if (!tim[i]) tarjan(i); printf("%d\n",ans); return 0; }