#include <bits/stdc++.h>
using namespace std;
class MaxFlow {
int V;
vector<vector<int>> capacity;
vector<vector<int>> adj;
public:
MaxFlow(int V) : V(V), capacity(V, vector<int>(V, 0)), adj(V) {}
void add_edge(int u, int v, int cap) {
capacity[u][v] = cap;
adj[u].push_back(v);
adj[v].push_back(u); // Reverse edge for residual graph
}
int bfs(int s, int t, vector<int>& parent) {
fill(parent.begin(), parent.end(), -1);
parent[s] = -2;
queue<pair<int, int>> q;
q.push({s, INT_MAX});
while (!q.empty()) {
int cur = q.front().first;
int flow = q.front().second;
q.pop();
for (int next : adj[cur]) {
if (parent[next] == -1 && capacity[cur][next] > 0) {
parent[next] = cur;
int new_flow = min(flow, capacity[cur][next]);
if (next == t)
return new_flow;
q.push({next, new_flow});
}
}
}
return 0;
}
int maxflow(int s, int t) {
int flow = 0;
vector<int> parent(V);
int new_flow;
while ((new_flow = bfs(s, t, parent))) {
flow += new_flow;
int cur = t;
while (cur != s) {
int prev = parent[cur];
capacity[prev][cur] -= new_flow;
capacity[cur][prev] += new_flow;
cur = prev;
}
}
return flow;
}
};
bool canForceLose(vector<pair<int, int>> &options, int which){
int n = options.size();
int votes = 0;
int source = 2 * n, sink = 2 * n + 1;
MaxFlow mf(2 * n + 2);
auto strategic = options[which];//this will be the last decision and is strategic
for (int i = 0; i < n; i++) {
if(i==which) continue;
auto pp = options[i];
if(pp.first == which || pp.second == which){
++votes;
}else{
mf.add_edge(source, i, 1);
mf.add_edge(i, pp.first + n, 1);
mf.add_edge(i, pp.second + n, 1);
}
}
for (int i = 0; i < n; i++) {
//you can vote at most (votes-1) times for non-strategic candidates
//but you can vote at most (votes-2) times for strategic candidates
//else that last strategic vote can overturn the election with a tie
int maxAllowedVotes = i==strategic.first || i == strategic.second ? votes-2 : votes-1;
if(maxAllowedVotes > 0) mf.add_edge(i + n, sink, maxAllowedVotes);
}
//could I assign all votes to a candidate while complying with the constraints?
return mf.maxflow(source, sink) + votes + 1 == n;//+1 because of the last strategic vote
}
int main(int argc, char* argv[]) {
vector<pair<int, int>> edges;
int n = 0;
cin>>n;
for(int i = 0;i<n;++i){
int a, b;
cin >> a >> b; --a;--b;
edges.emplace_back(a, b);
}
int ans = 0;
for(int i = 0;i<n;++i){
ans+=!canForceLose(edges, i);
}
cout<<ans<<endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY2xhc3MgTWF4RmxvdyB7CiAgICBpbnQgVjsKICAgIHZlY3Rvcjx2ZWN0b3I8aW50Pj4gY2FwYWNpdHk7CiAgICB2ZWN0b3I8dmVjdG9yPGludD4+IGFkajsKICAgIApwdWJsaWM6CiAgICBNYXhGbG93KGludCBWKSA6IFYoViksIGNhcGFjaXR5KFYsIHZlY3RvcjxpbnQ+KFYsIDApKSwgYWRqKFYpIHt9CgogICAgdm9pZCBhZGRfZWRnZShpbnQgdSwgaW50IHYsIGludCBjYXApIHsKICAgICAgICBjYXBhY2l0eVt1XVt2XSA9IGNhcDsKICAgICAgICBhZGpbdV0ucHVzaF9iYWNrKHYpOwogICAgICAgIGFkalt2XS5wdXNoX2JhY2sodSk7IC8vIFJldmVyc2UgZWRnZSBmb3IgcmVzaWR1YWwgZ3JhcGgKICAgIH0KCiAgICBpbnQgYmZzKGludCBzLCBpbnQgdCwgdmVjdG9yPGludD4mIHBhcmVudCkgewogICAgICAgIGZpbGwocGFyZW50LmJlZ2luKCksIHBhcmVudC5lbmQoKSwgLTEpOwogICAgICAgIHBhcmVudFtzXSA9IC0yOwogICAgICAgIHF1ZXVlPHBhaXI8aW50LCBpbnQ+PiBxOwogICAgICAgIHEucHVzaCh7cywgSU5UX01BWH0pOwoKICAgICAgICB3aGlsZSAoIXEuZW1wdHkoKSkgewogICAgICAgICAgICBpbnQgY3VyID0gcS5mcm9udCgpLmZpcnN0OwogICAgICAgICAgICBpbnQgZmxvdyA9IHEuZnJvbnQoKS5zZWNvbmQ7CiAgICAgICAgICAgIHEucG9wKCk7CgogICAgICAgICAgICBmb3IgKGludCBuZXh0IDogYWRqW2N1cl0pIHsKICAgICAgICAgICAgICAgIGlmIChwYXJlbnRbbmV4dF0gPT0gLTEgJiYgY2FwYWNpdHlbY3VyXVtuZXh0XSA+IDApIHsKICAgICAgICAgICAgICAgICAgICBwYXJlbnRbbmV4dF0gPSBjdXI7CiAgICAgICAgICAgICAgICAgICAgaW50IG5ld19mbG93ID0gbWluKGZsb3csIGNhcGFjaXR5W2N1cl1bbmV4dF0pOwogICAgICAgICAgICAgICAgICAgIGlmIChuZXh0ID09IHQpCiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBuZXdfZmxvdzsKICAgICAgICAgICAgICAgICAgICBxLnB1c2goe25leHQsIG5ld19mbG93fSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIDA7CiAgICB9CgogICAgaW50IG1heGZsb3coaW50IHMsIGludCB0KSB7CiAgICAgICAgaW50IGZsb3cgPSAwOwogICAgICAgIHZlY3RvcjxpbnQ+IHBhcmVudChWKTsKICAgICAgICBpbnQgbmV3X2Zsb3c7CgogICAgICAgIHdoaWxlICgobmV3X2Zsb3cgPSBiZnMocywgdCwgcGFyZW50KSkpIHsKICAgICAgICAgICAgZmxvdyArPSBuZXdfZmxvdzsKICAgICAgICAgICAgaW50IGN1ciA9IHQ7CiAgICAgICAgICAgIHdoaWxlIChjdXIgIT0gcykgewogICAgICAgICAgICAgICAgaW50IHByZXYgPSBwYXJlbnRbY3VyXTsKICAgICAgICAgICAgICAgIGNhcGFjaXR5W3ByZXZdW2N1cl0gLT0gbmV3X2Zsb3c7CiAgICAgICAgICAgICAgICBjYXBhY2l0eVtjdXJdW3ByZXZdICs9IG5ld19mbG93OwogICAgICAgICAgICAgICAgY3VyID0gcHJldjsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gZmxvdzsKICAgIH0KfTsKCmJvb2wgY2FuRm9yY2V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