Address: poj 2983
At the beginning of this question, I have no idea what relationship it has with the differential constraint system ..... Later, we found that we only needed to determine a negative ring ..
If there is a conflict, a negative ring will be formed. The reason why a positive value is added to the graph is that, in this case, data such as 1 2 4 and 1 2 3 will form a negative ring. This method is still clever... Then, for those unclear positions of V, an inequality will be formed together with those equations of P, and relaxation will be used to solve the problem in the process of judging the ring with the shortest short circuit.
The Code is as follows:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;const int INF=0x3f3f3f3f;int d[2000], head[2000], cnt, n;struct node{ int u, v, w, next;} edge[200000];void add(int u, int v, int w){ edge[cnt].u=u; edge[cnt].v=v; edge[cnt].w=w; edge[cnt].next=head[u]; head[u]=cnt++;}void berman(){ memset(d,INF,sizeof(d)); int i, j, flag, k; for(i=1; i<n; i++) { flag=0; for(j=0; j<=n; j++) { for(k=head[j]; k!=-1; k=edge[k].next) { int v=edge[k].v; if(d[v]>d[j]+edge[k].w) { d[v]=d[j]+edge[k].w; flag=1; } } } if(!flag) break; } flag=0; for(i=0; i<cnt; i++) { if(d[edge[i].v]>d[edge[i].u]+edge[i].w) { flag=1; break; } } if(flag) printf("Unreliable\n"); else printf("Reliable\n");}int main(){ int m, a, b, c, i; char ch; while(scanf("%d%d",&n,&m)!=EOF) { memset(head,-1,sizeof(head)); cnt=0; while(m--) { getchar(); scanf("%c",&ch); if(ch=='P') { scanf("%d%d%d",&a,&b,&c); add(a,b,-c); add(b,a,c); } else { scanf("%d%d",&a,&b); add(a,b,-1); } } berman(); } return 0;}
Poj 2983 is the information reliable? (Differential constraint system)