QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#504879#9102. Zayin and Elementsuntitledtwo#WA 2ms3860kbC++142.3kb2024-08-04 16:54:412024-08-04 16:54:41

Judging History

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

  • [2024-08-04 16:54:41]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3860kb
  • [2024-08-04 16:54:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int a[30], b[30], c[30];
bool isb[100010];
struct Edge
{
	int to, nxt, flow, val;
} e[100010];
int ecnt = 0, head[1010];
inline void addedge(int from, int to, int flow, int val, bool ib = false)
{
	e[ecnt].to = to;
	e[ecnt].flow = flow;
	e[ecnt].val = val;
	e[ecnt].nxt = head[from];
	isb[ecnt] = ib;
	head[from] = ecnt++;
}
inline void connect(int from, int to, int flow, int val)
{
	addedge(from, to, flow, val);
	addedge(to, from, 0, -val);
}
int n, m, s, t, pre[1010], lst[1010], dis[1010];
bool vis[1010];
const int INF = INT_MAX >> 1;
queue<int> q;
inline int spfa()
{
	for(int i = 0; i <= t; i++)
		dis[i] = INF, vis[i] = false;
	q.push(s);
	vis[s] = true, dis[s] = 0, pre[t] = -1;
	while(!q.empty())
	{
		int u = q.front();
		q.pop();
		vis[u] = false;
		for(int i = head[u]; i != -1; i = e[i].nxt)
		{
			int v = e[i].to;
			if(e[i].flow > 0 && dis[v] > dis[u] + e[i].val)
			{
				dis[v] = dis[u] + e[i].val;
				pre[v] = u, lst[v] = i;
				if(!vis[v])
				{
					vis[v] = true;
					q.push(v);
				}
			}
		}
	}
	return pre[t];
}
inline void Flow(int &maxflow, int &mincost)
{
	maxflow = mincost = 0;
	while(spfa() > 0)
	{
		int u = t;
		mincost += dis[t];
		maxflow++;
		while(u != s)
		{
			int v = pre[u], i = lst[u];
			e[i].flow--, e[i ^ 1].flow++;
			if(isb[i])
			{
				e[i].val = 999 - e[i].val;
			}
			u = v;
		}
	}
	mincost = (mincost + 999) / 1000;
}
int main()
{
	int T;
	scanf("%d", &T);
	while(T--)
	{
		scanf("%d %d", &n, &m);
		s = 0, t = n + 3 * m + 1;
		ecnt = 0;
		for(int i = 0; i <= t; i++)
			head[i] = -1;
		for(int i = 1; i <= n; i++)
			connect(s, i, 1, 0);
		int ans = 0;
		for(int i = 1; i <= m; i++)
		{
			scanf("%d %d %d", &a[i], &b[i], &c[i]);
			ans += b[i] + c[i];
			int k;
			scanf("%d", &k);
			while(k--)
			{
				int u;
				scanf("%d", &u);
				connect(u, i + n, 1, 0);
				connect(u, i + n + m, 1, 0);
				connect(u, i + n + m + m, 1, 0);
			}
			connect(i + n, t, a[i], 0);
			addedge(i + n + m, t, 2 * b[i], 999, true), addedge(t, i + n + m, 0, 0, true);
			addedge(i + n + m + m, t, c[i], 1000), addedge(t, i + n + m + m, c[i], 0);
		}
		int maxflow, mincost;
		Flow(maxflow, mincost);
		if(maxflow < n)
			printf("-1\n");
		else
			printf("%d\n", ans - mincost);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3836kb

input:

2
5
2
2 3 1 2 3 1
1 1 1 3 4 5 2
5
2
2 3 1 1 3
1 0 1 2 1 2

output:

5
-1

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3860kb

input:

5
9
10
0 0 10 2 3 8
0 0 10 2 4 6
0 8 2 2 2 4
0 0 10 3 1 3 8
0 4 6 2 2 3
0 8 2 3 2 6 7
0 9 1 2 1 7
0 2 8 3 1 4 9
0 7 3 1 5
0 0 10 3 5 6 9
3
10
0 9 1 1 2
0 5 5 1 1
0 1 9 1 1
0 7 3 1 1
0 7 3 0
0 0 10 0
0 6 4 1 3
0 9 1 0
0 7 3 0
0 9 1 1 2
90
20
0 6 4 12 1 4 5 22 32 64 66 67 73 87 88 89
0 1 9 12 3 8 21 3...

output:

94
97
155
151
151

result:

wrong answer 5th lines differ - expected: '152', found: '151'