Submission #1189664
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);
template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
EACH(x,vec) is >> x;
return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
REP(i,vec.size()) {
if (i) os << " ";
os << vec[i];
}
return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
REP(i,vec.size()) {
if (i) os << endl;
os << vec[i];
}
return os;
}
class MaxFlow {
struct Edge {
ll to, cap, rev;
};
bool is_debug;
ll V;
vector<vector<Edge>> G;
vector<ll> bfs(ll s) {
vector<ll> dist(V, linf);
dist[s] = 0;
queue<ll> Q; Q.push(s);
while ( !Q.empty() ) {
ll v = Q.front(); Q.pop();
EACH(e, G[v]) {
if (e.cap > 0 && dist[e.to] == linf) {
dist[e.to] = dist[v]+1;
Q.push(e.to);
}
}
}
return dist;
}
ll dfs(ll v, ll t, ll f, const vector<ll>& dist) {
if (v == t) return f;
EACH(e, G[v]) {
if (e.cap > 0 && dist[e.to] == dist[v]+1) {
ll d = dfs(e.to, t, min(f, e.cap), dist);
if (d > 0) {
e.cap -= d;
G[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
public:
const vector<vector<Edge>> Graph() {
return G;
}
MaxFlow(ll V, bool is_debug=false) : V(V), G(V), is_debug(is_debug) {}
void init(ll n) {
V = n;
G.assign(V, vector<Edge>());
}
void add(ll from, ll to, ll cap) {
if (is_debug) cout << "ADD: " << from << " " << to << " " << cap << endl;
assert(V > 0);
G[from].pb({to, cap, (ll)G[to].size()});
G[to].pb({from, 0, (ll)G[from].size()-1});
}
// S -> s, T -> t に inf は自力で
void add(ll from, ll to, ll min_flow, ll cap, ll S, ll T) {
if (is_debug) cout << endl << "ADD_MIN:" << from << " " << to << " " << min_flow << " " << cap << endl;
add(from, to, cap-min_flow);
add(S, to, min_flow);
add(from, T, cap);
if (is_debug) cout << endl;
}
ll flow(ll s, ll t, ll f=linf) {
ll res = 0;
while (f > 0) {
vector<ll> dist = bfs(s);
if (dist[t] == linf) break;
while (f > 0) {
ll df = dfs(s, t, f, dist);
if (df == 0) break;
f -= df;
res += df;
}
}
return res;
}
};
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
ll n, m, E; cin >> n >> m >> E;
vector<ll> mark(m); cin >> mark;
ll s = n;
MaxFlow mf(s+1);
REP(i, E) {
ll a, b; cin >> a >> b;
mf.add(a, b, 1);
mf.add(b, a, 1);
}
REP(i, m) {
mf.add(s, mark[i], 1);
}
cout << mf.flow(s, 0) << endl;
}
Submission Info
Submission Time |
|
Task |
D - 浮気予防 |
User |
drafear |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
3696 Byte |
Status |
AC |
Exec Time |
3 ms |
Memory |
896 KB |
Judge Result
Set Name |
part |
All |
Score / Max Score |
99 / 99 |
1 / 1 |
Status |
|
|
Set Name |
Test Cases |
part |
test_01_AB.txt, test_02_AB.txt, test_03_AB.txt, test_04_AB.txt, test_05_AB.txt, test_06_AB.txt, test_07_AB.txt, test_08_AB.txt, test_09_AB.txt, test_10_AB.txt, test_11_AB.txt, test_12_AB.txt, test_13_AB.txt, test_14_AB.txt, test_15_AB.txt, test_16_AB.txt, test_17_AB.txt, test_18_AB.txt, test_19_AB.txt, test_20_AB.txt, test_21_AB.txt, test_22_AB.txt, test_23_AB.txt, test_24_AB.txt, test_25_AB.txt, test_41_AB.txt, test_47_AB.txt |
All |
sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt, test_01_AB.txt, test_02_AB.txt, test_03_AB.txt, test_04_AB.txt, test_05_AB.txt, test_06_AB.txt, test_07_AB.txt, test_08_AB.txt, test_09_AB.txt, test_10_AB.txt, test_11_AB.txt, test_12_AB.txt, test_13_AB.txt, test_14_AB.txt, test_15_AB.txt, test_16_AB.txt, test_17_AB.txt, test_18_AB.txt, test_19_AB.txt, test_20_AB.txt, test_21_AB.txt, test_22_AB.txt, test_23_AB.txt, test_24_AB.txt, test_25_AB.txt, test_26_A.txt, test_27_A.txt, test_28_A.txt, test_29_A.txt, test_30_A.txt, test_31_A.txt, test_32_A.txt, test_33_A.txt, test_34_A.txt, test_35_A.txt, test_36_A.txt, test_37_A.txt, test_38_A.txt, test_39_A.txt, test_40_A.txt, test_41_AB.txt, test_42_A.txt, test_43_A.txt, test_44_A.txt, test_45_A.txt, test_46_A.txt, test_47_AB.txt, test_48_A.txt, test_49_A.txt, test_50_A.txt, test_51_A.txt |
Case Name |
Status |
Exec Time |
Memory |
sample_01.txt |
AC |
1 ms |
256 KB |
sample_02.txt |
AC |
1 ms |
256 KB |
sample_03.txt |
AC |
1 ms |
256 KB |
sample_04.txt |
AC |
1 ms |
256 KB |
sample_05.txt |
AC |
1 ms |
256 KB |
test_01_AB.txt |
AC |
1 ms |
256 KB |
test_02_AB.txt |
AC |
1 ms |
256 KB |
test_03_AB.txt |
AC |
1 ms |
256 KB |
test_04_AB.txt |
AC |
1 ms |
256 KB |
test_05_AB.txt |
AC |
1 ms |
256 KB |
test_06_AB.txt |
AC |
1 ms |
256 KB |
test_07_AB.txt |
AC |
1 ms |
256 KB |
test_08_AB.txt |
AC |
1 ms |
256 KB |
test_09_AB.txt |
AC |
1 ms |
256 KB |
test_10_AB.txt |
AC |
1 ms |
256 KB |
test_11_AB.txt |
AC |
1 ms |
256 KB |
test_12_AB.txt |
AC |
1 ms |
256 KB |
test_13_AB.txt |
AC |
1 ms |
256 KB |
test_14_AB.txt |
AC |
1 ms |
256 KB |
test_15_AB.txt |
AC |
1 ms |
256 KB |
test_16_AB.txt |
AC |
1 ms |
256 KB |
test_17_AB.txt |
AC |
1 ms |
256 KB |
test_18_AB.txt |
AC |
1 ms |
256 KB |
test_19_AB.txt |
AC |
1 ms |
256 KB |
test_20_AB.txt |
AC |
1 ms |
256 KB |
test_21_AB.txt |
AC |
1 ms |
256 KB |
test_22_AB.txt |
AC |
1 ms |
256 KB |
test_23_AB.txt |
AC |
1 ms |
256 KB |
test_24_AB.txt |
AC |
1 ms |
256 KB |
test_25_AB.txt |
AC |
1 ms |
256 KB |
test_26_A.txt |
AC |
2 ms |
896 KB |
test_27_A.txt |
AC |
3 ms |
896 KB |
test_28_A.txt |
AC |
3 ms |
896 KB |
test_29_A.txt |
AC |
3 ms |
896 KB |
test_30_A.txt |
AC |
2 ms |
896 KB |
test_31_A.txt |
AC |
3 ms |
896 KB |
test_32_A.txt |
AC |
1 ms |
384 KB |
test_33_A.txt |
AC |
2 ms |
640 KB |
test_34_A.txt |
AC |
1 ms |
384 KB |
test_35_A.txt |
AC |
2 ms |
384 KB |
test_36_A.txt |
AC |
1 ms |
384 KB |
test_37_A.txt |
AC |
2 ms |
512 KB |
test_38_A.txt |
AC |
1 ms |
256 KB |
test_39_A.txt |
AC |
1 ms |
256 KB |
test_40_A.txt |
AC |
1 ms |
256 KB |
test_41_AB.txt |
AC |
1 ms |
256 KB |
test_42_A.txt |
AC |
2 ms |
512 KB |
test_43_A.txt |
AC |
1 ms |
256 KB |
test_44_A.txt |
AC |
2 ms |
384 KB |
test_45_A.txt |
AC |
1 ms |
256 KB |
test_46_A.txt |
AC |
1 ms |
256 KB |
test_47_AB.txt |
AC |
1 ms |
256 KB |
test_48_A.txt |
AC |
1 ms |
256 KB |
test_49_A.txt |
AC |
1 ms |
256 KB |
test_50_A.txt |
AC |
1 ms |
256 KB |
test_51_A.txt |
AC |
1 ms |
256 KB |