• P1993 小K的农场


    P1993 小K的农场
    比较裸的差分约束,只是我判负环的时候sb了...

    有负环意味着无解

      1 #include<iostream>
      2 #include<cstdio>
      3 #include<queue>
      4 #include<algorithm>
      5 #include<cmath>
      6 #include<ctime>
      7 #include<set>
      8 #include<map>
      9 #include<stack>
     10 #include<cstring>
     11 #define inf 2147483647
     12 #define ls rt<<1
     13 #define rs rt<<1|1
     14 #define lson ls,nl,mid,l,r
     15 #define rson rs,mid+1,nr,l,r
     16 #define N 100010
     17 #define For(i,a,b) for(register int i=a;i<=b;i++)
     18 #define p(a) putchar(a)
     19 #define g() getchar()
     20 
     21 using namespace std;
     22 
     23 int n,m;
     24 int flag;
     25 bool Flag;
     26 int x,y,v;
     27 int d[100000];
     28 int num[100000];
     29 queue<int>q;
     30 bool vis[100000];
     31 
     32 struct node{
     33     int n;
     34     int v;
     35     node *next;
     36 }*e[1000000];
     37 
     38 void in(int &x){
     39     int y=1;
     40     char c=g();x=0;
     41     while(c<'0'||c>'9'){
     42         if(c=='-')y=-1;
     43         c=g();
     44     }
     45     while(c<='9'&&c>='0'){
     46         x=(x<<1)+(x<<3)+c-'0';c=g();
     47     }
     48     x*=y;
     49 }
     50 void o(int x){
     51     if(x<0){
     52         p('-');
     53         x=-x;
     54     }
     55     if(x>9)o(x/10);
     56     p(x%10+'0');
     57 }
     58 
     59 void push(int x,int y,int v){
     60     node *p;
     61     p=new node();
     62     p->n=y;
     63     p->v=v;
     64     if(e[x]==NULL)
     65         e[x]=p;
     66     else{
     67         p->next=e[x]->next;
     68         e[x]->next=p;
     69     }
     70 }
     71 
     72 inline void spfa(int x){
     73     if(vis[x]||Flag){
     74         Flag=true;
     75         return;
     76     }
     77     vis[x]=true;
     78     for(node *i=e[x];i;i=i->next){
     79         if(Flag)
     80             return;
     81         if(d[i->n]>d[x]+i->v){
     82             d[i->n]=d[x]+i->v;
     83             spfa(i->n);
     84         }
     85     }    
     86     vis[x]=false;
     87 }
     88 
     89 int main(){
     90     in(n);in(m);
     91     For(i,1,m){
     92         in(flag);
     93         in(x);in(y);
     94         if(flag!=3)
     95         in(v);
     96         if(flag==1)
     97             push(x,y,-v);
     98         if(flag==2)
     99             push(y,x,v);
    100         if(flag==3){
    101             push(x,y,0);
    102             push(y,x,0);
    103         }
    104     }
    105     For(i,1,n)
    106         push(0,i,0);
    107     For(i,1,n)
    108         d[i]=inf;
    109     spfa(0);
    110     if(!Flag)
    111         cout<<"Yes";
    112     else
    113         cout<<"No";
    114     return 0;
    115 }
    View Code
  • 相关阅读:
    在Raspberry上使用小度WIFI
    使用Doxyen和Graghviz为自己的库快速做个文档
    在Cocos2d-X中新建Android项目
    管理——执行
    windows环境下搭建Cocos2d-X开发环境
    Spark wordcount 编译错误 -- reduceByKey is not a member of RDD
    记录一次简单且容易犯的React Hook Router 相关错误
    关于微信浏览器H5页面软键盘关闭导致页面空缺
    【转载】关于vue-router的使用
    文字放大缩小
  • 原文地址:https://www.cnblogs.com/war1111/p/10369040.html
Copyright © 2020-2023  润新知