Submission #1592385
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,true):false;} template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,true):false;} int nextInt() { int x; scanf("%d", &x); return x;} const int MAX_V = 20000+5; typedef int CAP; const CAP INF = (int)1e9; struct Edge{ int dst; CAP cap; int rev; }; vector<Edge> adj[MAX_V]; int level[MAX_V]; int done[MAX_V]; void clearedge() { REP(i, MAX_V) adj[i].clear(); } void addedge(int u, int v, CAP c1, CAP c2) { adj[u].push_back( (Edge){v, c1, (int)adj[v].size() + (u == v)} ); adj[v].push_back( (Edge){u, c2, (int)adj[u].size() - 1} ); } CAP dinic_dfs(int v, CAP flow, int t) { if (v == t || flow == 0) return flow; for ( ; done[v] < (int)adj[v].size(); done[v]++) { Edge &e = adj[v][done[v]]; if (level[v] >= level[e.dst]) continue; CAP f = dinic_dfs(e.dst, min(flow, e.cap), t); if (f > 0) { e.cap -= f; adj[e.dst][e.rev].cap += f; return f; } } return 0; } bool dinic_bfs(int s, int t) { memset(level, -1, sizeof(level)); queue<int> q; q.push(s); level[s] = 0; while (!q.empty()) { int here = q.front(); q.pop(); for (const Edge &e : adj[here]) { if (e.cap > 0 && level[e.dst] == -1) { level[e.dst] = level[here] + 1; q.push(e.dst); } } } return level[t] >= 0; } CAP dinic(int s, int t) { CAP res = 0; while (dinic_bfs(s,t)) { memset(done, 0, sizeof(done)); for (CAP f; (f = dinic_dfs(s, INF, t)) > 0; ) res += f; } return res; } int main2() { clearedge(); int N = nextInt(); int G = nextInt(); int E = nextInt(); int s = 0; int t = N+1; REP(i, G) { int p = nextInt(); addedge(p, t, 1, 1); } REP(i, E) { int a = nextInt(); int b = nextInt(); addedge(a, b, 1, 1); } int f = dinic(s, t); cout << f << endl; return 0; } int main() { for (;!cin.eof();cin>>ws) main2(); return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - 浮気予防 |
User | hs484 |
Language | C++14 (GCC 5.4.1) |
Score | 100 |
Code Size | 2133 Byte |
Status | AC |
Exec Time | 3 ms |
Memory | 1024 KB |
Compile Error
./Main.cpp: In function ‘int nextInt()’: ./Main.cpp:9:39: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] int nextInt() { int x; scanf("%d", &x); return x;} ^
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 | 896 KB |
sample_02.txt | AC | 1 ms | 896 KB |
sample_03.txt | AC | 1 ms | 896 KB |
sample_04.txt | AC | 1 ms | 896 KB |
sample_05.txt | AC | 1 ms | 768 KB |
test_01_AB.txt | AC | 1 ms | 768 KB |
test_02_AB.txt | AC | 1 ms | 896 KB |
test_03_AB.txt | AC | 2 ms | 896 KB |
test_04_AB.txt | AC | 1 ms | 896 KB |
test_05_AB.txt | AC | 1 ms | 896 KB |
test_06_AB.txt | AC | 1 ms | 768 KB |
test_07_AB.txt | AC | 1 ms | 768 KB |
test_08_AB.txt | AC | 1 ms | 768 KB |
test_09_AB.txt | AC | 1 ms | 768 KB |
test_10_AB.txt | AC | 1 ms | 768 KB |
test_11_AB.txt | AC | 1 ms | 896 KB |
test_12_AB.txt | AC | 1 ms | 768 KB |
test_13_AB.txt | AC | 1 ms | 768 KB |
test_14_AB.txt | AC | 1 ms | 768 KB |
test_15_AB.txt | AC | 1 ms | 768 KB |
test_16_AB.txt | AC | 1 ms | 768 KB |
test_17_AB.txt | AC | 1 ms | 768 KB |
test_18_AB.txt | AC | 1 ms | 768 KB |
test_19_AB.txt | AC | 1 ms | 768 KB |
test_20_AB.txt | AC | 1 ms | 768 KB |
test_21_AB.txt | AC | 1 ms | 768 KB |
test_22_AB.txt | AC | 1 ms | 896 KB |
test_23_AB.txt | AC | 1 ms | 768 KB |
test_24_AB.txt | AC | 1 ms | 768 KB |
test_25_AB.txt | AC | 1 ms | 768 KB |
test_26_A.txt | AC | 2 ms | 1024 KB |
test_27_A.txt | AC | 2 ms | 1024 KB |
test_28_A.txt | AC | 3 ms | 1024 KB |
test_29_A.txt | AC | 2 ms | 1024 KB |
test_30_A.txt | AC | 2 ms | 1024 KB |
test_31_A.txt | AC | 2 ms | 1024 KB |
test_32_A.txt | AC | 1 ms | 896 KB |
test_33_A.txt | AC | 2 ms | 896 KB |
test_34_A.txt | AC | 1 ms | 896 KB |
test_35_A.txt | AC | 2 ms | 896 KB |
test_36_A.txt | AC | 1 ms | 896 KB |
test_37_A.txt | AC | 2 ms | 896 KB |
test_38_A.txt | AC | 1 ms | 896 KB |
test_39_A.txt | AC | 1 ms | 896 KB |
test_40_A.txt | AC | 1 ms | 896 KB |
test_41_AB.txt | AC | 1 ms | 768 KB |
test_42_A.txt | AC | 2 ms | 896 KB |
test_43_A.txt | AC | 1 ms | 896 KB |
test_44_A.txt | AC | 2 ms | 896 KB |
test_45_A.txt | AC | 1 ms | 896 KB |
test_46_A.txt | AC | 2 ms | 896 KB |
test_47_AB.txt | AC | 1 ms | 896 KB |
test_48_A.txt | AC | 1 ms | 896 KB |
test_49_A.txt | AC | 1 ms | 896 KB |
test_50_A.txt | AC | 1 ms | 896 KB |
test_51_A.txt | AC | 2 ms | 896 KB |