SWERC 2002 - Intervals (differential constraints)

Because the array size debug a long time ... because i + 1, so in the end to return 50001


template <typename T>
void write(T x) {
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
const int maxm=8000010;
const int maxn=50005;
const int inf=0x3f3f3f3f;
const int INF=0x7fffffff;
typedef long long ll;
bool vis[maxn];
struct node {
    int to,net,w;
}e[maxn*3];
int cnt,dis[maxn],head[maxn];
queue<int>que;
void add(int u,int v,int w) {
    e[cnt].to=v;
    e[cnt].w=w;
    e[cnt].net=head[u];
    head[u]=cnt++;
}
int spfa() {
    memset(dis,192,sizeof(dis));
    dis[0]=0;
    que.push(0);
    vis[0]=true;
    while(!que.empty()) {
        int k=que.front();
        que.pop();
        vis[k]=false;
        for(int i=head[k];i!=-1;i=e[i].net) {
            int v=e[i].to;
            if(dis[k]+e[i].w>dis[v]) {
                dis[v]=dis[k]+e[i].w;
                if(!vis[v]) {
                    que.push(v);
                    vis[v]=true;
                }
            }
        }
    }
    return dis[50001];
}
int main()
{
    memset(head,-1,sizeof(head));
    int m;
    for(int i=0;i<=50000;i++)
        add(i,i+1,0),add(i+1,i,-1);
    Read (m); 
    for (int I =. 1; I <= m; I ++) { 
        int U, V, W; 
        Read (U), Read (V), Read (W); 
        the Add (U, V +. 1, W); 
    } 
    Write (SPFA ()); PN; 
    return 0; 
} 
/// differential constraint: 
//1.t[i+1]-t[i]>=0 -> I built 0 to i + 1 side 
//2.t[i]-t[i+1]>=-1 -> i + 1 to i -1 built edge 
//3.t[b+1]-t[a]>=c - > a to b + 1 C side construction

  

Guess you like

Origin www.cnblogs.com/wuliking/p/11202982.html