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
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#ifdef LOC
#include "debuglib.h"
#else
#define deb(...)
#define DBP(...)
#endif
using namespace std;
using   ll         = long long;
using   Vi         = vector<int>;
using   Pii        = pair<int, int>;
#define pb           push_back
#define mp           make_pair
#define x            first
#define y            second
#define rep(i, b, e) for (int i = (b); i < (e); i++)
#define each(a, x)   for (auto& a : (x))
#define all(x)       (x).begin(), (x).end()
#define sz(x)        int((x).size())

struct Edge {
	int dst, rev;
	bool dir;
};

vector<vector<Edge>> G;
Vi prv, seen, que;
set<int> taken;
int cnt;

void addEdge(int u, int v) {
	G[u].pb({v, sz(G[v]), 1});
	G[v].pb({u, sz(G[u])-1, 0});
}

void flip(int v, int e) {
	auto &f = G[v][e];
	f.dir ^= 1;
	G[f.dst][f.rev].dir ^= 1;

	if (v == 0) {
		if (f.dir) {
			taken.erase(e);
		} else {
			taken.insert(e);
		}
	} else if (f.dst == 0) {
		if (f.dir) {
			taken.insert(f.rev);
		} else {
			taken.erase(f.rev);
		}
	}
}

void flipPath(int v) {
	while (prv[v] != -1) {
		flip(v, prv[v]);
		v = G[v][prv[v]].dst;
	}
}

void update() {
	int last = sz(G[0]);
	que.clear();
	prv[G[0].back().dst] = G[0].back().rev;
	seen[G[0].back().dst] = ++cnt;
	que.pb(G[0].back().dst);

	for (int pos = 0; pos < sz(que); pos++) {
		int v = que[pos];
		each(e, G[v]) if (e.dir) {
			if (e.dst == 0) {
				last = min(last, e.rev);
			} else if (seen[e.dst] != cnt) {
				prv[e.dst] = e.rev;
				if (e.dst == 1) {
					flipPath(1);
					return;
				}
				seen[e.dst] = cnt;
				que.pb(e.dst);
			}
		}
	}

	if (last < sz(G[0])) {
		flip(0, last);
		flipPath(G[0][last].dst);
	}
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cout << fixed << setprecision(12);

	int n, m, k;
	cin >> n >> m >> k;

	G.resize(n*2+2);
	rep(v, 1, n+1) addEdge(v*2, v*2+1);
	rep(v, 1, k+1) addEdge(v*2+1, 1);

	rep(i, 0, m) {
		int u, v;
		cin >> u >> v;
		addEdge(v*2+1, u*2);
	}

	vector<ll> ans(k+1);
	seen.assign(sz(G), -1);
	prv.assign(sz(G), -1);

	for (int v = n; v > k; v--) {
		addEdge(0, v*2);
		update();
		int i = 0, last = 0;
		for (auto it = taken.rbegin(); it != taken.rend(); it++) {
			int len = sz(G[0]) - *it - 1;
			ans[i++] += len - last;
			last = len;
		}
		ans[i] += sz(G[0]) - last;
	}

	each(a, ans) cout << a << '\n';
	return 0;
}