QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#699239#6766. Direction Settingbeamishboys#WA 1ms3632kbC++231.9kb2024-11-02 07:32:082024-11-02 07:32:08

Judging History

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

  • [2024-11-02 07:32:08]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3632kb
  • [2024-11-02 07:32:08]
  • 提交

answer

#include <iostream>
#include <vector>
#include <climits>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

struct Dinic {
	struct Edge {
		int to, rev;
		ll c, oc;
		ll flow() { return max(oc - c, 0LL); } // if you need flows
	};
	vi lvl, ptr, q;
	vector<vector<Edge>> adj;
	Dinic(int n) : lvl(n), ptr(n), q(n), adj(n) {}
	void addEdge(int a, int b, ll c, ll rcap = 0) {
		adj[a].push_back({b, sz(adj[b]), c, c});
		adj[b].push_back({a, sz(adj[a]) - 1, rcap, rcap});
	}
	ll dfs(int v, int t, ll f) {
		if (v == t || !f) return f;
		for (int& i = ptr[v]; i < sz(adj[v]); i++) {
			Edge& e = adj[v][i];
			if (lvl[e.to] == lvl[v] + 1)
				if (ll p = dfs(e.to, t, min(f, e.c))) {
					e.c -= p, adj[e.to][e.rev].c += p;
					return p;
				}
		}
		return 0;
	}
	ll calc(int s, int t) {
		ll flow = 0; q[0] = s;
		rep(L,0,31) do { // 'int L=30' maybe faster for random data
			lvl = ptr = vi(sz(q));
			int qi = 0, qe = lvl[s] = 1;
			while (qi < qe && !lvl[t]) {
				int v = q[qi++];
				for (Edge e : adj[v])
					if (!lvl[e.to] && e.c >> (30 - L))
						q[qe++] = e.to, lvl[e.to] = lvl[v] + 1;
			}
			while (ll p = dfs(s, t, LLONG_MAX)) flow += p;
		} while (lvl[t]);
		return flow;
	}
	bool leftOfMinCut(int a) { return lvl[a] != 0; }
};

int main() {
	int t; cin >> t;
	while (t--) {
		int n, m; cin >> n >> m;	
		Dinic flow(n+m+2);
		for (int i = 1; i <= n; i++) {
			int ai; cin >> ai;
			flow.addEdge(m+i, n+m+1, ai);
		}

		for (int i = 1; i <= m; i++) {
			int u, v; cin >> u >> v;
			flow.addEdge(i, m+u, 1);
			flow.addEdge(i, m+v, 1);
			flow.addEdge(0, i, 1);
		}
		flow.calc(0, n+m+1);
		for (int i = 1; i <= m; i++) {
			cout << 1-flow.adj[i][0].c;
		}
		cout << endl;
	}
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3632kb

input:

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

output:

00001
01

result:

wrong output format Expected integer, but "00001" found