n=int(input())
arr=[]
brr=[]
for _ in range(n):
a,b=map(int,input().split())
arr.append(a)
brr.append(b)
for i in range(n):
if (arr[i] in brr[:i] or arr[i] in brr[i+1:]):
n-=1
else:
continue
print(n)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
#include <any>
using namespace std;
#ifdef LOCAL
#define eprintf(...) \
{ \
fprintf(stderr, __VA_ARGS__); \
fflush(stderr); \
}
#else
#define eprintf(...) 42
#endif
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template <typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
int MOD = 1e9 + 7;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B)
{
return (ull)rng() % B;
}
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define print(...) cout << ... << endl;
#define nl "\n"
#define REPL(x, n) for(int x = 0; x < n; ++x)
clock_t startTime;
double getCurrentTime() {
return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
void printiv(vector<ll> v) {
for (int ele : v) {
cout << ele << " ";
}
cout << endl;
}
pair<int,int> arr[1001] {mp(-1, -1)};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
int a, b;
cin >> n;
unordered_set<int> needstobeopened = {};
REPL(i, n) {
cin >> a >> b;
arr[i] = mp(a, b);
needstobeopened.insert(i);
}
unordered_set<int> hasbeenopened = {};
stack<int> isopenedoniter = {};
int cnt = 0;
REPL(i, n) {
b = arr[i].second;
REPL(j, n) {
if(i == j) continue;
if (arr[j].first == b && (hasbeenopened.count(b) == 0 || needstobeopened.count(j) > 0)) {
//cout << b << nl;
cnt += 1;
needstobeopened.erase(j);
isopenedoniter.push(b);
}
}
while(!isopenedoniter.empty()) {
int tmp;
tmp = isopenedoniter.top();
isopenedoniter.pop();
hasbeenopened.insert(tmp);
}
}
cout << n - cnt << nl;
return 0;
}
2148. Count Elements With Strictly Smaller and Greater Elements | 2149. Rearrange Array Elements by Sign |
2150. Find All Lonely Numbers in the Array | 2151. Maximum Good People Based on Statements |
2144. Minimum Cost of Buying Candies With Discount | Non empty subsets |
1630A - And Matching | 1630B - Range and Partition |
1630C - Paint the Middle | 1630D - Flipping Range |
1328A - Divisibility Problem | 339A - Helpful Maths |
4A - Watermelon | 476A - Dreamoon and Stairs |
1409A - Yet Another Two Integers Problem | 977A - Wrong Subtraction |
263A - Beautiful Matrix | 180C - Letter |
151A - Soft Drinking | 1352A - Sum of Round Numbers |
281A - Word Capitalization | 1646A - Square Counting |
266A - Stones on the Table | 61A - Ultra-Fast Mathematician |
148A - Insomnia cure | 1650A - Deletions of Two Adjacent Letters |
1512A - Spy Detected | 282A - Bit++ |
69A - Young Physicist | 1651A - Playoff |