#include<bits/stdc++.h> using namespace std; #ifdef LOCAL template <class T, class U> auto &operator<<(ostream &out, pair<T, U> a) { return out << "(" << a.first << ", " << a.second << ")"; } template <class T, class = class enable_if<!is_same<T, string>(), class T::iterator>::type> auto &operator<<(ostream &out, T a) { out << "{"; bool fi = 1; for(auto b : a) { if(fi) {out<<b; fi=0;} else out<<", "<<b; } return out << "}"; } template <class T, class X, class Y> auto &operator<<(ostream &out, const priority_queue<T,X,Y>& a) {auto b = a; vector<T> v; while(!b.empty()) {v.push_back(b.top()); b.pop();} return out<<v; } void dump(){ cerr << "\e[39m"<<"\n"; } template <class T, class... Ts> void dump(T a, Ts... x) { cerr << a << ", "; dump(x...); } #define debug(...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<"[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__) #else #define debug(...) ; #endif template<class C> C reversed(C c) {reverse(c.begin(),c.end()); return c;} #define rep(i, n) for(int i=0;i<(int)(n);i++) #define all(X) (X).begin(), (X).end() #define mp make_pair #define st first #define nd second typedef long long ll; typedef pair<int,int> pii; struct Edge { int to; int cap; int rev; }; vector<vector<Edge> > graph; vector<int> visited; int vcnt = 1; int N; int findPath(int cur, int t, int ep) { if(cur == t) return 1e9; visited[cur] = ep; for(int i = graph[cur].size()-1; i>=0; i--) { auto& a = graph[cur][i]; if(a.cap && visited[a.to] != ep) { int x = findPath(a.to, t, ep); if(x) { x = min(x, a.cap); a.cap -= x; graph[a.to][a.rev].cap += x; return x; } } } return 0; } int ff(int s,int t) { int flow; int res = 0; while(flow = findPath(s,t, ++vcnt)) res += flow; return res; } void addEdge(int u, int v, int c=1, int rc=0) { assert(u != v); graph[u].push_back({v,c,graph[v].size()}); graph[v].push_back({u,rc,graph[u].size()-1}); } int flow(int s, int t, int L, int R) { auto gcp = graph; for(int i=L;i<=R;i++) addEdge(2*i, t); int res = ff(s,t); graph = gcp; return res; } int32_t main(){ ios::sync_with_stdio(false); cin.tie(0); int n,m,k; cin >> n >> m >> k; assert(n <= 2000); cerr<<n<<" "<<m<<" "<<k<<endl; // debug(n,m,k); N = n*2+2; graph.resize(N); visited.resize(N); int s = 0, t = N-1; for(int i=0;i<m;i++) { int a,b; cin >> a >> b; addEdge(2*a,2*b-1); } for(int i=1;i<=n;i++) { if(i <= k) addEdge(s, 2*i-1); addEdge(2*i-1, 2*i); } vector<ll> ans(k+2); for(int x=0;x<=k;x++) { int R = k+1; int b = k+1; for(int L=k+1;L<=n; L++) { while(b < L || (b <= n && flow(s,t,L,b) < x)) b++; while(R < b || (R <= n && flow(s,t,L,R) == x)) R++; ans[x] += R-b; } } for(int i=0;i<=k;i++) cout<<ans[i]<<"\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | #include<bits/stdc++.h> using namespace std; #ifdef LOCAL template <class T, class U> auto &operator<<(ostream &out, pair<T, U> a) { return out << "(" << a.first << ", " << a.second << ")"; } template <class T, class = class enable_if<!is_same<T, string>(), class T::iterator>::type> auto &operator<<(ostream &out, T a) { out << "{"; bool fi = 1; for(auto b : a) { if(fi) {out<<b; fi=0;} else out<<", "<<b; } return out << "}"; } template <class T, class X, class Y> auto &operator<<(ostream &out, const priority_queue<T,X,Y>& a) {auto b = a; vector<T> v; while(!b.empty()) {v.push_back(b.top()); b.pop();} return out<<v; } void dump(){ cerr << "\e[39m"<<"\n"; } template <class T, class... Ts> void dump(T a, Ts... x) { cerr << a << ", "; dump(x...); } #define debug(...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<"[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__) #else #define debug(...) ; #endif template<class C> C reversed(C c) {reverse(c.begin(),c.end()); return c;} #define rep(i, n) for(int i=0;i<(int)(n);i++) #define all(X) (X).begin(), (X).end() #define mp make_pair #define st first #define nd second typedef long long ll; typedef pair<int,int> pii; struct Edge { int to; int cap; int rev; }; vector<vector<Edge> > graph; vector<int> visited; int vcnt = 1; int N; int findPath(int cur, int t, int ep) { if(cur == t) return 1e9; visited[cur] = ep; for(int i = graph[cur].size()-1; i>=0; i--) { auto& a = graph[cur][i]; if(a.cap && visited[a.to] != ep) { int x = findPath(a.to, t, ep); if(x) { x = min(x, a.cap); a.cap -= x; graph[a.to][a.rev].cap += x; return x; } } } return 0; } int ff(int s,int t) { int flow; int res = 0; while(flow = findPath(s,t, ++vcnt)) res += flow; return res; } void addEdge(int u, int v, int c=1, int rc=0) { assert(u != v); graph[u].push_back({v,c,graph[v].size()}); graph[v].push_back({u,rc,graph[u].size()-1}); } int flow(int s, int t, int L, int R) { auto gcp = graph; for(int i=L;i<=R;i++) addEdge(2*i, t); int res = ff(s,t); graph = gcp; return res; } int32_t main(){ ios::sync_with_stdio(false); cin.tie(0); int n,m,k; cin >> n >> m >> k; assert(n <= 2000); cerr<<n<<" "<<m<<" "<<k<<endl; // debug(n,m,k); N = n*2+2; graph.resize(N); visited.resize(N); int s = 0, t = N-1; for(int i=0;i<m;i++) { int a,b; cin >> a >> b; addEdge(2*a,2*b-1); } for(int i=1;i<=n;i++) { if(i <= k) addEdge(s, 2*i-1); addEdge(2*i-1, 2*i); } vector<ll> ans(k+2); for(int x=0;x<=k;x++) { int R = k+1; int b = k+1; for(int L=k+1;L<=n; L++) { while(b < L || (b <= n && flow(s,t,L,b) < x)) b++; while(R < b || (R <= n && flow(s,t,L,R) == x)) R++; ans[x] += R-b; } } for(int i=0;i<=k;i++) cout<<ans[i]<<"\n"; } |