#include <bits/stdc++.h> #define PB push_back #define ST first #define ND second //#pragma GCC optimize ("O3") //#pragma GCC target("tune=native") //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; //typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; using namespace std; using ll = long long; using pi = pair<int, int>; using vi = vector<int>; const int nax = 1e5 + 10, mx = 1'500'000 + 10; int n, m, k; vi V[2*nax]; pi e[mx], einit[mx]; bool vis[2*nax]; int pre[2 * nax]; ll ans[60]; void dfs(int x) { vis[x] = true; for(int nbh : V[x]) { if(!vis[e[nbh].ND]) { pre[e[nbh].ND] = nbh; dfs(e[nbh].ND); } } } void reach() { for(int i = 0; i < 2*n; ++i) { vis[i] = false; } for(int i = 0; i < k; ++i) { if(!vis[2*i]) { dfs(2*i); } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> k; for(int a,b,i = 0; i < m; ++i) { cin >> a >> b; a--; b--; V[a*2+1].PB(i); V[b*2].PB(i); e[i] = {a*2+1, b*2}; einit[i] = e[i]; } for(int i = m; i < m + n; ++i) { V[(i - m) * 2].PB(i); V[(i - m) * 2 + 1].PB(i); e[i] = {(i - m) * 2, (i - m) * 2 + 1}; einit[i] = e[i]; } for(int l = k + 1; l <= n; ++l) { for(int i = 0; i < m + n; ++i) { e[i] = einit[i]; } reach(); int cnt = 0; for(int r = l; r <= n; ++r) { int id = (r - 1) * 2 + 1; if(vis[id]) { cnt++; while(id % 2 == 1 || id > 2 * (k - 1)) { int ed = pre[id]; id = e[ed].ST; swap(e[ed].ST, e[ed].ND); } reach(); } ans[cnt]++; } } 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 | #include <bits/stdc++.h> #define PB push_back #define ST first #define ND second //#pragma GCC optimize ("O3") //#pragma GCC target("tune=native") //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; //typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; using namespace std; using ll = long long; using pi = pair<int, int>; using vi = vector<int>; const int nax = 1e5 + 10, mx = 1'500'000 + 10; int n, m, k; vi V[2*nax]; pi e[mx], einit[mx]; bool vis[2*nax]; int pre[2 * nax]; ll ans[60]; void dfs(int x) { vis[x] = true; for(int nbh : V[x]) { if(!vis[e[nbh].ND]) { pre[e[nbh].ND] = nbh; dfs(e[nbh].ND); } } } void reach() { for(int i = 0; i < 2*n; ++i) { vis[i] = false; } for(int i = 0; i < k; ++i) { if(!vis[2*i]) { dfs(2*i); } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> k; for(int a,b,i = 0; i < m; ++i) { cin >> a >> b; a--; b--; V[a*2+1].PB(i); V[b*2].PB(i); e[i] = {a*2+1, b*2}; einit[i] = e[i]; } for(int i = m; i < m + n; ++i) { V[(i - m) * 2].PB(i); V[(i - m) * 2 + 1].PB(i); e[i] = {(i - m) * 2, (i - m) * 2 + 1}; einit[i] = e[i]; } for(int l = k + 1; l <= n; ++l) { for(int i = 0; i < m + n; ++i) { e[i] = einit[i]; } reach(); int cnt = 0; for(int r = l; r <= n; ++r) { int id = (r - 1) * 2 + 1; if(vis[id]) { cnt++; while(id % 2 == 1 || id > 2 * (k - 1)) { int ed = pre[id]; id = e[ed].ST; swap(e[ed].ST, e[ed].ND); } reach(); } ans[cnt]++; } } for(int i = 0; i <= k; ++i) { cout << ans[i] << "\n"; } } |