Submission #1370828


Source Code Expand

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

class LazySegTree{
private:
	int n;
	vector<ll> node, lazy;
	vector<bool> lazyFlag;
public:
	LazySegTree(vector<ll> v){
		int sz = v.size();
		n = 1; while(n < sz) n *= 2;
		node.resize(2*n-1, 0);
		lazy.resize(2*n-1, 0);
		lazyFlag.resize(2*n-1, false);
		REP(i, sz) node[i+n-1] = v[i];
		for(int i = n-2;i >= 0;i--) node[i] = node[2*i+1]+node[2*i+2];
	}

	void eval(int k, int l, int r){
		if(lazyFlag[k]){
			node[k] += lazy[k] * (r-l);
			if(r-l > 1){
				lazy[2*k+1] += lazy[k];
				lazy[2*k+2] += lazy[k];
				lazyFlag[2*k+1] = lazyFlag[2*k+2] = true;
			}
			lazy[k] = 0;
			lazyFlag[k] = false;
		}
	}

	void add(int a, int b, ll x, int k=0, int l=0, int r=-1){
		if(r < 0) r = n;
		eval(k, l, r);
		if(b <= l || r <= a) return;

		if(a <= l && r <= b){
			lazy[k] += x;
			lazyFlag[k] = true;
			eval(k, l, r);
		}else{
			add(a, b, x, k*2+1, l, (l+r)/2);
			add(a, b, x, k*2+2, (l+r)/2, r);
			node[k] = node[k*2+1] + node[k*2+2];
		}
	}

	ll query(int a, int b, int k=0, int l=0, int r=-1){
		if(r < 0) r = n;
		eval(k, l, r);

		if(b <= l || r <= a) return 0;
		if(a <= l && r <= b) return node[k];

		return query(a, b, k*2+1, l, (l+r)/2) + query(a, b, k*2+2, (l+r)/2, r);
	}
};

class Bucket{
private:
	int n, bs, bn;
	vector<ll> data;
	vector<ll> bucket, lazy;
	vector<bool> lazyFlag;
public:
	Bucket(vector<ll> v, int sz){
		data = v;
		n = v.size();
		bs = sz;
		bn = (n + bs - 1) / bs;
		data.resize(bn*bs, INF_LL);
		bucket.assign(bn, INF_LL);
		lazy.assign(bn, 0);
		lazyFlag.assign(bn, 0);
		REP(i, bn){
			ll minx = INF_LL;
			REP(j, bs){
				chmin(minx, data[i*bs+j]);
			}
			bucket[i] = minx;
		}
	}

	void eval(int k){
		if(lazyFlag[k]){
			lazyFlag[k] = false;
			FOR(i, bs*k, bs*(k+1)){
				data[i] = lazy[k];
			}
			lazy[k] = 0;
		}
	}

	void update(int s, int t, int x){
		REP(k, bn){
			int l = k*bs, r = (k+1)*bs;
			if(r <= s || t <= l) continue;
			if(s <= l && r <= t){
				lazyFlag[k] = true;
				bucket[k] = x;
				lazy[k] = x;
			}else{
				eval(k);
				FOR(i, max(s, l), min(t, r)){
					data[i] = x;
				}
				bucket[k] = INF_LL;
				FOR(i, l, r){
					chmin(bucket[k], data[i]);
				}
			}
		}
	}

	ll query(int s, int t){
		ll res = INF_LL;
		REP(k, bn){
			int l = k*bs, r = (k+1)*bs;
			if(r <= s || t <= l) continue;
			if(s <= l && r <= t){
				chmin(res, bucket[k]);
			}else{
				eval(k);
				FOR(i, max(s, l), min(t, r)){
					chmin(res, data[i]);
				}
			}
		}
		return res;
	}

};

struct edge{int to, cap, rev; };

vector<edge> G[110];
int level[110];
int iter[110];

void add_edge(int from, int to, int cap){
	G[from].push_back((edge){to, cap, static_cast<int>(G[to].size())});
	G[to].push_back((edge){from, 0, static_cast<int>(G[from].size()-1)});
}

void bfs(int s){
	memset(level, -1, sizeof level);
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while(que.size()){
		int v = que.front(); que.pop();
		REP(i, G[v].size()){
			edge &e = G[v][i];
			if(e.cap > 0 && level[e.to] < 0){
				level[e.to] = level[v]+1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v, int t, int f){
	if(v == t) return f;
	for(int &i = iter[v];i < G[v].size();i++){
		edge &e = G[v][i];
		if(e.cap > 0 && level[v] < level[e.to]){
			int d = dfs(e.to, t, min(f, e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t){
	int flow = 0;
	while(1){
		bfs(s);
		if(level[t] < 0) return flow;
		memset(iter, 0, sizeof iter);
		int f;
		while((f = dfs(s, t, INF)) > 0){
			flow += f;
		}
	}
}

int main(void){
	int N, G, E;
	cin >> N >> G >> E;
	REP(i, G){
		int p;
		cin >> p;
		add_edge(p, N, 1);
	}
	REP(i, E){
		int a, b;
		cin >> a >> b;
		add_edge(a, b, 1);
		add_edge(b, a, 1);
	}
	cout << max_flow(0, N) << endl;
}

Submission Info

Submission Time
Task D - 浮気予防
User maze1230
Language C++14 (GCC 5.4.1)
Score 100
Code Size 5197 Byte
Status AC
Exec Time 4 ms
Memory 640 KB

Judge Result

Set Name part All
Score / Max Score 99 / 99 1 / 1
Status
AC × 27
AC × 61
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 4 ms 640 KB
test_27_A.txt AC 4 ms 640 KB
test_28_A.txt AC 4 ms 640 KB
test_29_A.txt AC 4 ms 640 KB
test_30_A.txt AC 4 ms 640 KB
test_31_A.txt AC 4 ms 640 KB
test_32_A.txt AC 2 ms 256 KB
test_33_A.txt AC 3 ms 384 KB
test_34_A.txt AC 1 ms 256 KB
test_35_A.txt AC 2 ms 256 KB
test_36_A.txt AC 2 ms 256 KB
test_37_A.txt AC 2 ms 384 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 384 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