63pts 求调
查看原帖
63pts 求调
674247
seanlsy楼主2022/7/19 15:24

WA 了第 2,11,12,13,142,11,12,13,14 个点

#include <bits/stdc++.h>
using namespace std;
int n,m1,m2,u,v,w,sh[1005],vis[1005],s;
bitset<1005> bt;
struct edge
{
  int dis,v;
};
vector<edge> g[1005];//用于存边
inline int spfa(int x)
{  
  memset(sh,63,sizeof sh);
  memset(vis,0,sizeof(vis));
  bt.reset();
  sh[x]=0,bt[x]=vis[x]=1;
  queue<int> q;
  q.push(x);
  while(q.size())
  {
    u=q.front();
    q.pop();
    bt[u]=0;
    for(int i=0; i<g[u].size(); i++)
    {
      edge y=g[u][i];
      if(sh[y.v]>sh[u]+y.dis)
      {
        sh[y.v]=sh[u]+y.dis;
        if(!bt[y.v])
        {
//          printf("vis[%d]=%d\n",y.v,vis[y.v]);
          q.push(y.v);
          if(++vis[y.v]>n) return -1;
          bt[y.v]=1;
        }
      }
    }
  }
  return (sh[n]>1e7?-2:sh[n]);
}
int main()
{
  cin>>n>>m1>>m2;
  while(m1--)
  {
    cin>>u>>v>>w;
    g[u].push_back((edge){w,v});
  } 
  while(m2--){
  	cin>>u>>v>>w;
    g[v].push_back((edge){-w,u});
  }
  for(int i=1;i<n;i++)
  	g[i+1].push_back((edge){0,i});
  for(int i=1; i<=n; i++)
    g[0].push_back((edge){0,i});
  if(s=spfa(0)<0) return !printf("%d\n",s);
  printf("%d\n",spfa(1));
  return 0;
}
/*
10 15 20
5 9 1207
3 9 1900
5 6 336
4 6 692
7 8 314
1 9 2460
3 6 1029
6 7 230
2 3 318
6 10 1225
5 10 1558
8 9 336
4 8 1230
3 10 2251
1 8 1815
4 10 1907
4 9 1556
3 8 1560
2 6 1337
2 4 648
2 10 2560
1 8 2121
6 8 535
5 8 868
5 7 558
7 10 991
1 3 556
8 10 680
2 8 1875
3 5 688
1 2 242
1 5 1249
1 10 2805
3 4 334
7 9 640
这里是 #2
*/ 
2022/7/19 15:24
加载中...