QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#155479#6870. Coinneko_nyaaCompile Error//C++232.8kb2023-09-01 17:52:322023-09-01 17:52:33

Judging History

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

  • [2023-09-01 17:52:33]
  • 评测
  • [2023-09-01 17:52:32]
  • 提交

answer

#include <bits/stdc++.h>
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 int 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, int 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; }
};

void solve() {
	int n, m, k; cin >> n >> m >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<pair<int, int>> edges;
	vector<vector<int>> needs(n);
	for (int i = 0; i < n; i++) {
		needs[i].push_back(0);
	}
	for (int i = 0; i < m; i++) {
		int x, y; cin >> x >> y; x--, y--;
		edges.emplace_back(x, y);
		needs[x].push_back(i+1);
		needs[y].push_back(i+1);
	}
	for (int i = 0; i < n; i++) {
		needs[i].push_back(m+1);
	}

	vector<int> fr(n);
	for (int i = 0; i < k; i++) {
		int x; cin >> x; x--; fr[x] = 1;
	}

	int sz = 2 + 2*n + 4*m;
	Dinic dc(sz);
	map<pair<int, int>, int> id;
	int source = 0, sink = sz-1;

	int petr = 1; // source = 1, sink = sz-1
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < needs[i].size(); j++) {
			id[{i, needs[i][j]}] = petr; 
			petr++;
		}
		
		dc.addEdge(source, id[{i, needs[i][0]}], 1);
		if (fr[i]) dc.addEdge(id[{i, needs[i].back()}], sink, a[i]);
		for (int j = 1; j < needs[i].size(); j++) {
			dc.addEdge(id[{i, needs[i][j-1]}], id[{i, needs[i][j]}], a[i]);
		}
	}

	for (int i = 1; i <= m; i++) {
		auto [x, y] = edges[i-1];
		dc.addEdge(id[{x, i}], id[{y, i}], 1);
		dc.addEdge(id[{y, i}], id[{x, i}], 1);
	}

	cout << dc.calc(source, sink) << '\n';
}

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);

	int t; cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}

Details

answer.code: In member function ‘ll Dinic::Edge::flow()’:
answer.code:15:39: error: no matching function for call to ‘max(ll, long long int)’
   15 |                 ll flow() { return max(oc - c, 0LL); } // if you need flows
      |                                    ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
answer.code:15:39: note:   deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘long long int’)
   15 |                 ll flow() { return max(oc - c, 0LL); } // if you need flows
      |                                    ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_algobase.h:300:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
answer.code:15:39: note:   deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘long long int’)
   15 |                 ll flow() { return max(oc - c, 0LL); } // if you need flows
      |                                    ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_algo.h:3461:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)’
 3461 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3461:5: note:   template argument deduction/substitution failed:
answer.code:15:39: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘int’
   15 |                 ll flow() { return max(oc - c, 0LL); } // if you need flows
      |                                    ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_algo.h:3467:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)’
 3467 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3467:5: note:   template argument deduction/substitution failed:
answer.code:15:39: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘int’
   15 |                 ll flow() { return max(oc - c, 0LL); } // if you need flows
      |                                    ~~~^~~~~~~~~~~~~
answer.code: In member function ‘ll Dinic::calc(int, int)’:
answer.code:47:49: warning: overflow in conversion from ‘long long int’ to ‘ll’ {aka ‘int’} changes value from ‘9223372036854775807’ to ‘-1’ [-Woverflow]
   47 |                         while (ll p = dfs(s, t, LLONG_MAX)) flow += p;
      |                                                 ^~~~~~~~~