#2 错误,差分约束做法,求调

P2294 [HNOI2005] 狡猾的商人

@ clear123666 cnt[j]++应该放在if(!st[j])里边吧 原本: ```cpp cnt[j]++; if(cnt[j]>=n+1)return false; if(!st[j]){ q.push(j); st[j]=true; } ``` 应该为: ```cpp if(!st[j]){ cnt[j]++; if(cnt[j]>=n+1)return false; q.push(j); st[j]=true; } ```
by superkkkeee @ 2024-04-04 17:59:10


@[clear123666](/user/1229671)
by superkkkeee @ 2024-04-04 17:59:37


@[superkkkeee](/user/777848) 谢谢你的指正,但#2 仍然是错的 [这是我的答题结果](https://www.luogu.com.cn/record/154287325)
by clear123666 @ 2024-04-04 19:07:04


@[clear123666](/user/1229671) 试试long long?
by superkkkeee @ 2024-04-04 19:09:07


改过了,你看看 ```cpp #include<iostream> #include<algorithm> #include<cstring> #include<queue> using namespace std; #define int long long //here const int N = 10010,M = 20010; int e[M],ne[M],w[M],cnt[N],idx,h[N]; bool st[N]; int T; int dist[N]; int n,m; void add(int a,int b,int c){ e[idx]=b,w[idx]=c,ne[idx]=h[a],h[a]=idx++; } bool spfa(){ memset(dist,-0x3f,sizeof dist); memset(st,0,sizeof st); memset(cnt,0,sizeof cnt); queue<int>q; q.push(n+1); dist[n+1]=0; st[n+1]=true; //cnt[n+1]++; while(q.size()){ int t=q.front(); q.pop(); st[t]=false; for(int i=h[t];~i;i=ne[i]){ int j=e[i]; if(dist[j]<dist[t]+w[i]){ dist[j]=dist[t]+w[i]; if(cnt[j]>=n+1)return false; if(!st[j]){cnt[j]++; //here q.push(j); st[j]=true; } } } } return true; } signed main(){ cin>>T; while(T--){ idx=0; memset(h,-1,sizeof h); cin>>n>>m; for(int i=1;i<=m;i++){ int a,b,c; cin>>a>>b>>c; add(a-1,b,c); add(b,a-1,-c); } for(int i=0;i<=n;i++){ add(n+1,i,0); } if(!spfa())puts("false"); else puts("true"); } return 0; } ```
by superkkkeee @ 2024-04-04 19:11:55


@[superkkkeee](/user/777848) 貌似还是错的 [具体](https://www.luogu.com.cn/record/154287937)
by clear123666 @ 2024-04-04 19:12:05


改过了 @[clear123666](/user/1229671) 其实 ```cpp if(cnt[j]>=n+1)return false; ``` 并不用放在判断里
by superkkkeee @ 2024-04-04 19:18:24


@[superkkkeee](/user/777848) [好像还是错的](https://www.luogu.com.cn/record/154288958)
by clear123666 @ 2024-04-04 19:21:05


[啊???](https://www.luogu.com.cn/record/154288294) (本人小号)
by superkkkeee @ 2024-04-04 19:22:40


@[clear123666](/user/1229671)
by superkkkeee @ 2024-04-04 19:22:52


| 下一页