zoukankan      html  css  js  c++  java
  • 【JZOJ4857】Tourist Attractions(Bitset)

    题意:给定一个n个点的无向图,求这个图中有多少条长度为4的简单路径。

    n<=1500

    思路:

     1 #include<map>
     2 #include<set>
     3 #include<cmath>
     4 #include<cstdio>
     5 #include<vector>
     6 #include<cstring>
     7 #include<cstdlib>
     8 #include<iostream>
     9 #include<algorithm>
    10 #include<bitset>
    11 #define MAXN 1510
    12 #define MAXM 4100000
    13 using namespace std;
    14 
    15 typedef long long ll;
    16 bitset<MAXN> a[MAXN],tmp;
    17 
    18 int head[MAXM],vet[MAXM],next[MAXM],n,i,j,tot;
    19 ll size[MAXN];
    20 ll ans;
    21 
    22 void add(int a,int b)
    23 {
    24   next[++tot]=head[a];
    25   vet[tot]=b;
    26   head[a]=tot;
    27 }
    28 
    29 int main()
    30 {
    31     //freopen("jzoj4857.in","r",stdin);
    32     //freopen("jzoj4857.out","w",stdout);
    33     scanf("%d",&n);
    34     for(int i=1;i<=n;i++)
    35     {
    36         scanf("
    ");
    37         for(int j=1;j<=n;j++) 
    38         {
    39             char ch;
    40             scanf("%c",&ch);
    41             if(ch=='1')
    42              {
    43                 add(i,j);
    44                 size[i]++;
    45                 a[i][j]=1;
    46              }
    47                 
    48         }
    49     }
    50     for(int i=1;i<=n;i++)
    51      for(int e=head[i];e;e=next[e])
    52      {
    53          int v=vet[e];
    54          ans+=(size[i]-1)*(size[v]-1);
    55          tmp=a[i]&a[v];
    56          ans-=tmp.count();
    57      }
    58      printf("%lld
    ",ans);
    59      return 0;
    60 }
  • 相关阅读:
    3.16 使用Zookeeper对HDFS HA配置自动故障转移及测试
    4、html的body内标签之input系列
    Gym
    Gym
    Gym
    Gym
    Gym
    Big Event in HDU HDU1171 (多重背包)
    Coins POJ 1742 多重背包部分和
    HDU 1059 Dividing 多重背包
  • 原文地址:https://www.cnblogs.com/myx12345/p/9267964.html
Copyright © 2011-2022 走看看