QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#43659#3249. 分组作业_DuskerWA 129ms53532kbC++142.9kb2022-08-09 21:32:082022-08-09 21:32:11

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-09 21:32:11]
  • 评测
  • 测评结果:WA
  • 用时:129ms
  • 内存:53532kb
  • [2022-08-09 21:32:08]
  • 提交

answer

#include<bits/stdc++.h>
#define ioclear std::ios::sync_with_stdio(false);std::cin.tie(nullptr);std::cout.tie(nullptr);
#define endl '\n'
#define int long long

using i64 = long long;

template<typename T> 
struct Flow
{
	static constexpr T inf = 0x3f3f3f3f3f3f3f;
	static constexpr int mmax = 1e6 + 10;
	int n, m, s, t;
	T dis[mmax], ptr[mmax];
    Flow(int _n, int _m, int _s, int _t) : n(_n), m(_m), s(_s), t(_t) {}
	Flow() {}
	struct node
	{
		int from, to;
		T cap, flow;
		node() {}
		node(int u, int v, T w, T f) : from(u), to(v), cap(w), flow(f) {}
	};
	std::vector<node> edge;
	std::vector<int> no[mmax];

	void set(int _n, int _m, int _s, int _t) {n = _n, m = _m, s = _s, t = _t;}

	void add(int u, int v, T w)
	{
		no[u].push_back(edge.size());
		edge.push_back({u, v, w, 0});
		no[v].push_back(edge.size());
		edge.push_back({v, u, 0, 0});
		return;
	}

	bool bfs()
	{
		memset(dis, -1, sizeof dis);
		dis[s] = 0;
		std::queue<int> q;
		q.push(s);
		while(!q.empty())
		{
			int v = q.front();
			q.pop();
			if(v == t) return 1;
			for(auto i : no[v])
			{
				int to = edge[i].to;
				if(dis[to] == -1 && edge[i].flow < edge[i].cap)
					dis[to] = dis[v] + 1, q.push(to);
			}
		}
		return 0;
	}

	T dfs(int cur, T maxf)
	{
		if(maxf <= 0) return 0;
		if(cur == t) return maxf;
		for(;ptr[cur] < no[cur].size();ptr[cur]++)
		{
			int id = no[cur][ptr[cur]], to = edge[id].to;
			if(dis[to] != dis[cur] + 1) continue;
			T pushed = dfs(to, std::min(maxf, edge[id].cap - edge[id].flow) );
			if(pushed)
			{
				edge[id].flow += pushed;
				edge[id ^ 1].flow -= pushed;
				return pushed;
			}
		}
		return 0;
	}

	T dinic()
	{
		T Ans = 0, val;
		while(bfs())
		{
			memset(ptr, 0, sizeof ptr);
			while(val = dfs(s, inf) )
				Ans += val;
		}
		return Ans;
	}
};

int n, m;
Flow<i64> f;
std::unordered_map<int, int> mp;

signed main()
{
    #ifdef ONLINE_JUDGE
    ioclear;
    #endif

    std::cin >> n >> m;
    int S = 0, T = 4 * n + m;
    f.set(n, m, S, T);
    for(int i = 1;i <= 2 * n;i++)
    {
        int c, d, e;
        std::cin >> c >> d >> e;
        f.add(S, i, d);
        f.add(i, S, 0);
        f.add(i, T, c);
        f.add(T, i, 0);
        if(i & 1)
            f.add(i, i + 1, e), f.add(i + 1, i, 0);
        else
            f.add(i, i - 1, e), f.add(i - 1, i, 0);
        //f.add(i, i+1, e);
    }
    for(int i = 1;i <= 2 * n;i += 2)
    {
        int id = n + ((i + 1) >> 1);
        mp[i] = mp[i + 1] = id;
        f.add(id, i, f.inf);
        f.add(i, id, 0);
        f.add(id, i + 1, f.inf);
        f.add(i + 1, id, 0);
    }
    for(int i = 1;i <= m;i++)
    {
        int A, B, a, b;
        std::cin >> A >> B >> a >> b;
        int ida = mp[A], idb = mp[B];
        f.add(idb, A, b);
        f.add(A, idb, 0);
        f.add(B, ida, a);
        f.add(ida, B, 0);
    }
    std::cout << f.dinic();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 129ms
memory: 53532kb

input:

5000 10000
23060775 12 2
255978380 28 517
5 6624 26
151149 45131806 23849036
489 484971 24970
162846 1993316 188305
56311199 2003 211
1 50534913 517527
364913 882765 298
71 26 122914059
13 65459 18150033
20 607 8
380059068 3873712 228
9813 5449 6370
3309369 37410691 8
181 1 62340851
1705 4 107
8 209...

output:

66518055494

result:

wrong answer 1st lines differ - expected: '22929674417', found: '66518055494'