zoukankan      html  css  js  c++  java
  • codevs 4246

    round4粗略地看了下。。2道数论我就不想做了(其实是要赶集地补作业)

    权值并查集。。。做过食物链了再做感觉不乱了。。

    然而爆0?输出调试没删掉真是日了狗了QAQ

    还是先滚去搞初赛吧。。。再加上作业仍未补完= =

     1 #include<bits/stdc++.h>
     2 #define inc(i,l,r) for(i=l;i<=r;i++)
     3 #define dec(i,l,r) for(i=l;i>=r;i--)
     4 #define inf 1e9
     5 #define mem(a) memset(a,0,sizeof(a))
     6 #define ll long long
     7 #define succ(x) (1<<x)
     8 #define NM 5000
     9 using namespace std;
    10 int read(){
    11     int x=0,f=1;char ch=getchar();
    12     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    13     while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    14     return x*f;
    15 }
    16 int f[NM],a[NM],m,n,T,_x,_y,v,i,flag,fx,fy,b[NM];
    17 int find(int x){
    18     if(f[x]==x)return x;
    19     int t=f[x];
    20     f[x]=find(f[x]);
    21     a[x]=a[x]+a[t]-b[x];
    22     b[x]=a[f[x]];
    23     return f[x];
    24 }
    25 int main(){
    26     T=read();
    27     while(T--){
    28         mem(a);mem(f);flag=false;
    29         n=read();m=read();
    30         inc(i,1,n)f[i]=i;
    31         inc(i,1,m){
    32             _x=read();_y=read();v=read();
    33             if(find(_x)==find(_y)){
    34                 if(a[_y]-a[_x]!=v)flag=true;
    35             }else{
    36                 fx=find(_x);fy=find(_y);
    37                 f[fx]=fy;b[fx]=a[fy];a[fx]=a[fx]+a[_y]-v-a[_x];
    38             }
    39 //            if(flag)printf("Bessie is blind.
    ");
    40 //            else printf("Bessie's eyes are good
    ");
    41         }
    42         if(flag)printf("Bessie is blind.
    ");
    43         else printf("Bessie's eyes are good
    ");
    44     }
    45     return 0;
    46 }
    View Code
  • 相关阅读:
    数据分析三剑客 numpy,oandas,matplotlib(2)
    数据分析三剑客 numpy,oandas,matplotlib
    爬虫 crawlSpider 分布式 增量式 提高效率
    RestTemplate:带 header 的 get 请求
    Java:md5 摘要
    Java:Base64 编码
    Java:将字符串转换为枚举
    RestTemplate:使用 Map 传递参数
    Spring cloud:网关-Zuul路由
    Spring cloud:熔断器-Hystrix Dashboard
  • 原文地址:https://www.cnblogs.com/onlyRP/p/4857502.html
Copyright © 2011-2022 走看看