CF 20C

WA 很多次,原因出在inf设定太小了,以后果断用<climits>头文件中的LLONG_MAX,ULLONG_MAX,INT_MAX之类的表示无穷大吧,不然遇上这类坑题绝对给跪

代码:

#include <iostream>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#define esp 1e-6
#define pb push_back
#define in  freopen("in.txt", "r", stdin);
#define out freopen("out.txt", "w", stdout);
#define print(a) printf("%d\n",(a));
#define bug puts("********))))))");
#define Rep(i, c) for(__typeof(c.end()) i = c.begin(); i != c.end(); i++)
#define inf LLONG_MAX
#define INF 0x0f0f0f0f0f0f
#define N 100010
#define M 2000100
using namespace std;
typedef __int64 LL;
typedef vector<int> VI;
typedef vector<int>:: iterator IT;
struct EDGE{
int i, c, d;
EDGE *nxt, *ani;
} *Edge[N], *Path[N], E[M];
LL dis[N], cnt;
bool inq[N];
int n, m, sink, src;
VI ans;
void add(int i, int j, int c, int d, EDGE &e1, EDGE &e2)
{
    e1.i = j, e1.c = c, e1.d = d, e1.nxt = Edge[i], e1.ani = &e2, Edge[i] = &e1;
    e2.i = i, e2.c = 0, e2.d = -d, e2.nxt = Edge[j], e2.ani = &e1, Edge[j] = &e2;
}
void init(void)
{
    cnt = 0;
    memset(Edge, 0, sizeof(Edge));
}
bool SPFA(int s, int end)
{
    for(int i = 0; i < N; i++)
        dis[i] = inf;
    queue<int> q;
    int Max = dis[0];
    dis[s] = 0;
    inq[s] = true;
    q.push(s);
    while(!q.empty())
    {
        int u = q.front();
        int v;
        q.pop();
        inq[u] = 0;
        for(EDGE *p = Edge[u]; p; p = p->nxt)
        {
            if(p->c && dis[v = p->i] > dis[u] + p->d)
                if(Path[v] = p, dis[v] = dis[u] + p->d, !inq[v])
                 inq[v] = 1, q.push(v);
        }
    }
    return dis[end] < inf;
}
bool min_cost_flow(int s, int end)
{
    if(SPFA(s, end))
    {
        for(EDGE *p = Path[end]; p; p = Path[p->ani->i])
        {
            if(p->i != sink)
            ans.pb(p->i);
        }
        return 1;
    }
        else return 0;
}
int main(void)
{
    scanf("%d%d", &n, &m);
    src = 0, sink = n + 1;
    for(int i = 1; i <= m; i++)
    {
        int u, v, w;
        scanf("%d%d%d", &u, &v, &w);
        add(u, v, 1, w, E[cnt], E[cnt + 1]);
        cnt += 2;
        add(v, u, 1, w, E[cnt], E[cnt + 1]);
        cnt += 2;
    }
    add(src, 1, 1, 0, E[cnt], E[cnt + 1]);
    cnt += 2;
    add(n, sink, 1, 0, E[cnt], E[cnt + 1]);
    cnt += 2;
   int ret = min_cost_flow(src, sink);
   if(ret)
   {
       for(int i = ans.size() - 1; i >= 0; i--)
        printf("%d%c", ans[i], (i == 0) ? '\n' : ' ');
   }
   else puts("-1");
    return 0;
}




{ "header": { "desc": "success", "failures": [ ], "oprs": 1, "succ": 1, "oprtime": 1, "quota": 1, "rquota": 200000000, "status": 0, "traceid": "c704b56386e611f0b7ced3f6e79c6a59" }, "body": { "data": [ { "videoid": 6180739146, "userid": 52024476, "videoName": "auto_7619_2025-08-30", "url": "http://vcp.baidu.com/c21b214d8912cf7ba8efbfc20c53a7da.mp4", "videoMd5": "c21b214d8912cf7ba8efbfc20c53a7da", "content": "{\"format\":\"mov,mp4,m4a,3gp,3g2,mj2\",\"capacity\":15.00788688659668,\"height\":1280,\"width\":720,\"bitRate\":3491.867,\"frameRate\":30.0,\"audioRate\":317.375,\"duration\":33,\"thumbnail\":\"http://vcp.baidu.com/c21b214d8912cf7ba8efbfc20c53a7da.png\",\"videoCodec\":\"h264\",\"audioCodec\":\"aac\",\"videoRate\":3491.867}", "videoContentMd5": "ca1f6dba8514235949db9e0ffb886904", "auditContent": "", "source": 2, "format": "mp4", "capacity": 15.00788688659668, "height": 1280, "width": 720, "bitRate": 3491.867, "frameRate": 30, "audioRate": 317.375, "duration": 33, "thumbnail": "http://vcp.baidu.com/c21b214d8912cf7ba8efbfc20c53a7da.png", "addTime": "Sep 1, 2025 11:50:19 AM", "modTime": "Sep 1, 2025 11:50:19 AM", "auditStatus": 2, "rsnid": 0, "reasonText": "", "robotStatus": 30, "uploadStatus": 0, "outerUrl": "http://vision.bj.bcebos.com/c21b214d8912cf7ba8efbfc20c53a7da.mp4", "videoCodec": "h264", "audioCodec": "aac", "videoRate": 3491.867, "previewUrl": "http://vcp.baidu.com/c21b214d8912cf7ba8efbfc20c53a7da.mp4", "videoId": 6180739146, "userId": 52024476 } ], "expand": { } } }这段json字符串转为java实体类
09-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值