#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) (x & (-x))
#define BIT(a,b) ((ll)(a&(1<<b))==0 ? false : true)

const ll MAXN=2e5+10;
const ll INF=1e12+10;

set <pll> e[MAXN];

vector <pll> h[MAXN];

vector <ll> vertex[MAXN];
vector <ll> floor_g[MAXN];
vector <ll> child[MAXN];

ll dp[MAXN];
ll head[MAXN];
ll len[MAXN];
ll floor_v[MAXN];
ll back_edge[MAXN];
ll par[MAXN];

bool check[MAXN];

ll maxf=0;

void dsu(ll v , ll u)
{
    if ((ll)(e[v].size())>(ll)(e[u].size()))
    {
        while (!e[u].empty())
        {
            set <pll> :: iterator i=e[u].begin();

            pll a=(*i);
            a.X=1-a.X;

            if (e[v].find(a)!=e[v].end())
            {
                e[v].erase(a);
            }
            else
            {
                e[v].insert(*i);
            }

            e[u].erase(i);
        }
    }
    else
    {
        while (!e[v].empty())
        {
            set <pll> :: iterator i=e[v].begin();

            pll a=(*i);
            a.X=1-a.X;

            if (e[u].find(a)!=e[u].end())
            {
                e[u].erase(a);
            }
            else
            {
                e[u].insert(*i);
            }

            e[v].erase(i);
        }

        e[v].swap(e[u]);
    }
}

void fill_dp(ll f)
{
    for(ll i=0;i<floor_g[f].size();i++)
    {
        ll v=floor_g[f][i];

        for (ll j=0;j<h[v].size();j++)
        {
            e[v].insert(h[v][j]);
        }

        dp[v]=back_edge[v];

        for(ll j=0;j<child[v].size();j++)
        {
            dp[v]=min(dp[v] , dp[child[v][j]]);

            dsu(v , child[v][j]);
        }

        if (f==0 && (ll)(e[v].size())!=0)
        {
            cout<<"PNo";
            exit(0);
        }

        if (dp[v]>=f)
        {
            //cout<<":D "<<v<<" "<<dp[v]<<" "<<back_edge[v]<<" "<<e[v].size()<<" ";
            ll c=0;

            set <pll> :: iterator a=upper_bound(e[v].begin() , e[v].end() , mp((ll)0 , (ll)(-1)));
            set <pll> :: iterator b=upper_bound(e[v].begin() , e[v].end() , mp((ll)1 , (ll)(-1)));

            //cout<<a->X<<" "<<a->Y<<" :P "<<b->X<<" "<<b->Y<<endl;

            if (a!=e[v].end() && (a->X)==0)
            {
                c++;
            }

            if (b!=e[v].end() && (b->X)==1)
            {
                c++;
            }

            if (c==2)
            {
                cout<<"No";
                exit(0);
            }
        }
    }
}

void dfs(ll v , ll f)
{
    back_edge[v]=f;

    check[v]=true;

    if (f>=maxf)
    {
        maxf=f;
        floor_g[f].clear();
    }

    floor_g[f].pb(v);
    floor_v[v]=f;

    bool t=false;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i]])
        {
            par[vertex[v][i]]=v;

            dfs(vertex[v][i] , f+1);

            child[v].pb(vertex[v][i]);
        }
        else
        {
            if (!t && vertex[v][i]==par[v])
            {
                t=true;
                continue;
            }

            back_edge[v]=min(back_edge[v] , floor_v[vertex[v][i]]);
        }
    }
}

void ok(ll v)
{
    maxf=0;

    dfs(v , 0);

    for(ll i=maxf;i>=0;i--)
    {
        fill_dp(i);
    }
}

void update(ll v)
{
    if (head[head[v]]!=head[v])
    {
        update(head[v]);
    }

    head[v]=head[head[v]];
}

void pre_dsu(ll v , ll u)
{
    update(v);
    update(u);

    if (head[v]==head[u])
    {
        return;
    }

    if (len[head[v]]<len[head[u]])
    {
        head[head[v]]=head[u];
        len[head[u]]+=len[head[v]];
    }
    else
    {
        head[head[u]]=head[v];
        len[head[v]]+=len[head[u]];
    }
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);

    ll n,m,q;
    cin>>n>>m>>q;

    for(ll i=1;i<=n;i++)
    {
        head[i]=i;
        len[i]=1;
    }

    for(ll i=0;i<m;i++)
    {
        ll v,u;
        cin>>v>>u;

        vertex[v].pb(u);
        vertex[u].pb(v);

        pre_dsu(v , u);
    }

    for(ll i=1;i<=n;i++)
    {
        update(i);
    }

    for(ll i=0;i<q;i++)
    {
        ll v,u;
        cin>>v>>u;

        if (n>100 && (v==1 || u==1))
        {
            continue;
        }

        h[v].pb(mp(0 , i));
        h[u].pb(mp(1 , i));

        if (head[v]!=head[u])
        {
            cout<<"No";
            return 0;
        }
    }

    for(ll i=1;i<=n;i++)
    {
        if (!check[i])
        {
            ok(i);
        }
    }

    cout<<"Yes";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) (x & (-x))
#define BIT(a,b) ((ll)(a&(1<<b))==0 ? false : true)

const ll MAXN=2e5+10;
const ll INF=1e12+10;

set <pll> e[MAXN];

vector <pll> h[MAXN];

vector <ll> vertex[MAXN];
vector <ll> floor_g[MAXN];
vector <ll> child[MAXN];

ll dp[MAXN];
ll head[MAXN];
ll len[MAXN];
ll floor_v[MAXN];
ll back_edge[MAXN];
ll par[MAXN];

bool check[MAXN];

ll maxf=0;

void dsu(ll v , ll u)
{
    if ((ll)(e[v].size())>(ll)(e[u].size()))
    {
        while (!e[u].empty())
        {
            set <pll> :: iterator i=e[u].begin();

            pll a=(*i);
            a.X=1-a.X;

            if (e[v].find(a)!=e[v].end())
            {
                e[v].erase(a);
            }
            else
            {
                e[v].insert(*i);
            }

            e[u].erase(i);
        }
    }
    else
    {
        while (!e[v].empty())
        {
            set <pll> :: iterator i=e[v].begin();

            pll a=(*i);
            a.X=1-a.X;

            if (e[u].find(a)!=e[u].end())
            {
                e[u].erase(a);
            }
            else
            {
                e[u].insert(*i);
            }

            e[v].erase(i);
        }

        e[v].swap(e[u]);
    }
}

void fill_dp(ll f)
{
    for(ll i=0;i<floor_g[f].size();i++)
    {
        ll v=floor_g[f][i];

        for (ll j=0;j<h[v].size();j++)
        {
            e[v].insert(h[v][j]);
        }

        dp[v]=back_edge[v];

        for(ll j=0;j<child[v].size();j++)
        {
            dp[v]=min(dp[v] , dp[child[v][j]]);

            dsu(v , child[v][j]);
        }

        if (f==0 && (ll)(e[v].size())!=0)
        {
            cout<<"PNo";
            exit(0);
        }

        if (dp[v]>=f)
        {
            //cout<<":D "<<v<<" "<<dp[v]<<" "<<back_edge[v]<<" "<<e[v].size()<<" ";
            ll c=0;

            set <pll> :: iterator a=upper_bound(e[v].begin() , e[v].end() , mp((ll)0 , (ll)(-1)));
            set <pll> :: iterator b=upper_bound(e[v].begin() , e[v].end() , mp((ll)1 , (ll)(-1)));

            //cout<<a->X<<" "<<a->Y<<" :P "<<b->X<<" "<<b->Y<<endl;

            if (a!=e[v].end() && (a->X)==0)
            {
                c++;
            }

            if (b!=e[v].end() && (b->X)==1)
            {
                c++;
            }

            if (c==2)
            {
                cout<<"No";
                exit(0);
            }
        }
    }
}

void dfs(ll v , ll f)
{
    back_edge[v]=f;

    check[v]=true;

    if (f>=maxf)
    {
        maxf=f;
        floor_g[f].clear();
    }

    floor_g[f].pb(v);
    floor_v[v]=f;

    bool t=false;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i]])
        {
            par[vertex[v][i]]=v;

            dfs(vertex[v][i] , f+1);

            child[v].pb(vertex[v][i]);
        }
        else
        {
            if (!t && vertex[v][i]==par[v])
            {
                t=true;
                continue;
            }

            back_edge[v]=min(back_edge[v] , floor_v[vertex[v][i]]);
        }
    }
}

void ok(ll v)
{
    maxf=0;

    dfs(v , 0);

    for(ll i=maxf;i>=0;i--)
    {
        fill_dp(i);
    }
}

void update(ll v)
{
    if (head[head[v]]!=head[v])
    {
        update(head[v]);
    }

    head[v]=head[head[v]];
}

void pre_dsu(ll v , ll u)
{
    update(v);
    update(u);

    if (head[v]==head[u])
    {
        return;
    }

    if (len[head[v]]<len[head[u]])
    {
        head[head[v]]=head[u];
        len[head[u]]+=len[head[v]];
    }
    else
    {
        head[head[u]]=head[v];
        len[head[v]]+=len[head[u]];
    }
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);

    ll n,m,q;
    cin>>n>>m>>q;

    for(ll i=1;i<=n;i++)
    {
        head[i]=i;
        len[i]=1;
    }

    for(ll i=0;i<m;i++)
    {
        ll v,u;
        cin>>v>>u;

        vertex[v].pb(u);
        vertex[u].pb(v);

        pre_dsu(v , u);
    }

    for(ll i=1;i<=n;i++)
    {
        update(i);
    }

    for(ll i=0;i<q;i++)
    {
        ll v,u;
        cin>>v>>u;

        if (v==1 || u==1)
        {
            continue;
        }

        h[v].pb(mp(0 , i));
        h[u].pb(mp(1 , i));

        if (head[v]!=head[u])
        {
            cout<<"No";
            return 0;
        }
    }

    for(ll i=1;i<=n;i++)
    {
        if (!check[i])
        {
            ok(i);
        }
    }

    cout<<"Yes";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) (x & (-x))
#define BIT(a,b) ((ll)(a&(1<<b))==0 ? false : true)

const ll MAXN=2e5+10;
const ll INF=1e12+10;

set <pll> e[MAXN];

vector <pll> h[MAXN];

vector <ll> vertex[MAXN];
vector <ll> floor_g[MAXN];
vector <ll> child[MAXN];

ll dp[MAXN];
ll head[MAXN];
ll len[MAXN];
ll floor_v[MAXN];
ll back_edge[MAXN];
ll par[MAXN];

bool check[MAXN];

ll maxf=0;

void dsu(ll v , ll u)
{
    if ((ll)(e[v].size())>(ll)(e[u].size()))
    {
        while (!e[u].empty())
        {
            set <pll> :: iterator i=e[u].begin();

            pll a=(*i);
            a.X=1-a.X;

            if (e[v].find(a)!=e[v].end())
            {
                e[v].erase(a);
            }
            else
            {
                e[v].insert(*i);
            }

            e[u].erase(i);
        }
    }
    else
    {
        while (!e[v].empty())
        {
            set <pll> :: iterator i=e[v].begin();

            pll a=(*i);
            a.X=1-a.X;

            if (e[u].find(a)!=e[u].end())
            {
                e[u].erase(a);
            }
            else
            {
                e[u].insert(*i);
            }

            e[v].erase(i);
        }

        e[v].swap(e[u]);
    }
}

void fill_dp(ll f)
{
    for(ll i=0;i<floor_g[f].size();i++)
    {
        ll v=floor_g[f][i];

        for (ll j=0;j<h[v].size();j++)
        {
            e[v].insert(h[v][j]);
        }

        dp[v]=back_edge[v];

        for(ll j=0;j<child[v].size();j++)
        {
            dp[v]=min(dp[v] , dp[child[v][j]]);

            dsu(v , child[v][j]);
        }

        if (f==0 && (ll)(e[v].size())!=0)
        {
            cout<<v<<" PNo";
            exit(0);
        }

        if (dp[v]>=f)
        {
            //cout<<":D "<<v<<" "<<dp[v]<<" "<<back_edge[v]<<" "<<e[v].size()<<" ";
            ll c=0;

            set <pll> :: iterator a=upper_bound(e[v].begin() , e[v].end() , mp((ll)0 , (ll)(-1)));
            set <pll> :: iterator b=upper_bound(e[v].begin() , e[v].end() , mp((ll)1 , (ll)(-1)));

            //cout<<a->X<<" "<<a->Y<<" :P "<<b->X<<" "<<b->Y<<endl;

            if (a!=e[v].end() && (a->X)==0)
            {
                c++;
            }

            if (b!=e[v].end() && (b->X)==1)
            {
                c++;
            }

            if (c==2)
            {
                cout<<"No";
                exit(0);
            }
        }
    }
}

void dfs(ll v , ll f)
{
    back_edge[v]=f;

    check[v]=true;

    if (f>=maxf)
    {
        maxf=f;
        floor_g[f].clear();
    }

    floor_g[f].pb(v);
    floor_v[v]=f;

    bool t=false;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i]])
        {
            par[vertex[v][i]]=v;

            dfs(vertex[v][i] , f+1);

            child[v].pb(vertex[v][i]);
        }
        else
        {
            if (!t && vertex[v][i]==par[v])
            {
                t=true;
                continue;
            }

            back_edge[v]=min(back_edge[v] , floor_v[vertex[v][i]]);
        }
    }
}

void ok(ll v)
{
    maxf=0;

    dfs(v , 0);

    for(ll i=maxf;i>=0;i--)
    {
        fill_dp(i);
    }
}

void update(ll v)
{
    if (head[head[v]]!=head[v])
    {
        update(head[v]);
    }

    head[v]=head[head[v]];
}

void pre_dsu(ll v , ll u)
{
    update(v);
    update(u);

    if (head[v]==head[u])
    {
        return;
    }

    if (len[head[v]]<len[head[u]])
    {
        head[head[v]]=head[u];
        len[head[u]]+=len[head[v]];
    }
    else
    {
        head[head[u]]=head[v];
        len[head[v]]+=len[head[u]];
    }
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);

    ll n,m,q;
    cin>>n>>m>>q;

    for(ll i=1;i<=n;i++)
    {
        head[i]=i;
        len[i]=1;
    }

    for(ll i=0;i<m;i++)
    {
        ll v,u;
        cin>>v>>u;

        vertex[v].pb(u);
        vertex[u].pb(v);

        pre_dsu(v , u);
    }

    for(ll i=1;i<=n;i++)
    {
        update(i);
    }

    for(ll i=0;i<q;i++)
    {
        ll v,u;
        cin>>v>>u;

        h[v].pb(mp(0 , i));
        h[u].pb(mp(1 , i));

        if (head[v]!=head[u])
        {
            cout<<"No";
            return 0;
        }
    }

    for(ll i=1;i<=n;i++)
    {
        if (!check[i])
        {
            ok(i);
        }
    }

    cout<<"Yes";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) (x & (-x))
#define BIT(a,b) ((ll)(a&(1<<b))==0 ? false : true)

const ll MAXN=2e5+10;
const ll INF=1e12+10;

set <pll> e[MAXN];

vector <pll> h[MAXN];

vector <ll> vertex[MAXN];
vector <ll> floor_g[MAXN];
vector <ll> child[MAXN];

ll dp[MAXN];
ll head[MAXN];
ll len[MAXN];
ll floor_v[MAXN];
ll back_edge[MAXN];
ll par[MAXN];

bool check[MAXN];

ll maxf=0;

void dsu(ll v , ll u)
{
    if ((ll)(e[v].size())>(ll)(e[u].size()))
    {
        while (!e[u].empty())
        {
            set <pll> :: iterator i=e[u].begin();

            pll a=(*i);
            a.X=1-a.X;

            if (e[v].find(a)!=e[v].end())
            {
                e[v].erase(a);
            }
            else
            {
                e[v].insert(*i);
            }

            e[u].erase(i);
        }
    }
    else
    {
        while (!e[v].empty())
        {
            set <pll> :: iterator i=e[v].begin();

            pll a=(*i);
            a.X=1-a.X;

            if (e[u].find(a)!=e[u].end())
            {
                e[u].erase(a);
            }
            else
            {
                e[u].insert(*i);
            }

            e[v].erase(i);
        }

        e[v].swap(e[u]);
    }
}

void fill_dp(ll f)
{
    for(ll i=0;i<floor_g[f].size();i++)
    {
        ll v=floor_g[f][i];

        for (ll j=0;j<h[v].size();j++)
        {
            e[v].insert(h[v][j]);
        }

        dp[v]=back_edge[v];

        for(ll j=0;j<child[v].size();j++)
        {
            dp[v]=min(dp[v] , dp[child[v][j]]);

            dsu(v , child[v][j]);
        }

        if (f==0 && (ll)(e[v].size())!=0)
        {
            cout<<"No";
            exit(0);
        }

        if (dp[v]>=f)
        {
            //cout<<":D "<<v<<" "<<dp[v]<<" "<<back_edge[v]<<" "<<e[v].size()<<" ";
            ll c=0;

            set <pll> :: iterator a=upper_bound(e[v].begin() , e[v].end() , mp((ll)0 , (ll)(-1)));
            set <pll> :: iterator b=upper_bound(e[v].begin() , e[v].end() , mp((ll)1 , (ll)(-1)));

            //cout<<a->X<<" "<<a->Y<<" :P "<<b->X<<" "<<b->Y<<endl;

            if (a!=e[v].end() && (a->X)==0)
            {
                c++;
            }

            if (b!=e[v].end() && (b->X)==1)
            {
                c++;
            }

            if (c==2)
            {
                cout<<"No";
                exit(0);
            }
        }
    }
}

void dfs(ll v , ll f)
{
    back_edge[v]=f;

    check[v]=true;

    if (f>=maxf)
    {
        maxf=f;
        floor_g[f].clear();
    }

    floor_g[f].pb(v);
    floor_v[v]=f;

    bool t=false;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i]])
        {
            par[vertex[v][i]]=v;

            dfs(vertex[v][i] , f+1);

            child[v].pb(vertex[v][i]);
        }
        else
        {
            if (!t && vertex[v][i]==par[v])
            {
                t=true;
                continue;
            }

            back_edge[v]=min(back_edge[v] , floor_v[vertex[v][i]]);
        }
    }
}

void ok(ll v)
{
    maxf=0;

    dfs(v , 0);

    for(ll i=maxf;i>=0;i--)
    {
        fill_dp(i);
    }
}

void update(ll v)
{
    if (head[head[v]]!=head[v])
    {
        update(head[v]);
    }

    head[v]=head[head[v]];
}

void pre_dsu(ll v , ll u)
{
    update(v);
    update(u);

    if (head[v]==head[u])
    {
        return;
    }

    if (len[head[v]]<len[head[u]])
    {
        head[head[v]]=head[u];
        len[head[u]]+=len[head[v]];
    }
    else
    {
        head[head[u]]=head[v];
        len[head[v]]+=len[head[u]];
    }
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);

    ll n,m,q;
    cin>>n>>m>>q;

    for(ll i=1;i<=n;i++)
    {
        head[i]=i;
        len[i]=1;
    }

    for(ll i=0;i<m;i++)
    {
        ll v,u;
        cin>>v>>u;

        vertex[v].pb(u);
        vertex[u].pb(v);

        pre_dsu(v , u);
    }

    for(ll i=1;i<=n;i++)
    {
        update(i);
    }

    for(ll i=0;i<q;i++)
    {
        ll v,u;
        cin>>v>>u;

        h[v].pb(mp(0 , i));
        h[u].pb(mp(1 , i));

        if (head[v]!=head[u])
        {
            cout<<"No";
            return 0;
        }
    }

    for(ll i=1;i<=n;i++)
    {
        if (!check[i])
        {
            ok(i);
        }
    }

    cout<<"Yes";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) (x & (-x))
#define BIT(a,b) ((ll)(a&(1<<b))==0 ? false : true)

const ll MAXN=2e5+10;
const ll INF=1e12+10;

set <pll> e[MAXN];

vector <pll> h[MAXN];

vector <ll> vertex[MAXN];
vector <ll> floor_g[MAXN];
vector <ll> child[MAXN];

ll dp[MAXN];
ll head[MAXN];
ll len[MAXN];
ll floor_v[MAXN];
ll back_edge[MAXN];
ll par[MAXN];

bool check[MAXN];

ll maxf=0;

void dsu(ll v , ll u)
{
    if ((ll)(e[v].size())>(ll)(e[u].size()))
    {
        while (!e[u].empty())
        {
            set <pll> :: iterator i=e[u].begin();

            pll a=(*i);
            a.X=1-a.X;

            if (e[v].find(a)!=e[v].end())
            {
                e[v].erase(a);
            }
            else
            {
                e[v].insert(*i);
            }

            e[u].erase(i);
        }
    }
    else
    {
        while (!e[v].empty())
        {
            set <pll> :: iterator i=e[v].begin();

            pll a=(*i);
            a.X=1-a.X;

            if (e[u].find(a)!=e[u].end())
            {
                e[u].erase(a);
            }
            else
            {
                e[u].insert(*i);
            }

            e[v].erase(i);
        }

        e[v].swap(e[u]);
    }
}

void fill_dp(ll f)
{
    for(ll i=0;i<floor_g[f].size();i++)
    {
        ll v=floor_g[f][i];

        for (ll j=0;j<h[v].size();j++)
        {
            e[v].insert(h[v][j]);
        }

        dp[v]=back_edge[v];

        for(ll j=0;j<child[v].size();j++)
        {
            dp[v]=min(dp[v] , dp[child[v][j]]);

            dsu(v , child[v][j]);
        }

        if (dp[v]>=f)
        {
            //cout<<":D "<<v<<" "<<dp[v]<<" "<<back_edge[v]<<" "<<e[v].size()<<" ";
            ll c=0;

            set <pll> :: iterator a=upper_bound(e[v].begin() , e[v].end() , mp((ll)0 , (ll)(-1)));
            set <pll> :: iterator b=upper_bound(e[v].begin() , e[v].end() , mp((ll)1 , (ll)(-1)));

            //cout<<a->X<<" "<<a->Y<<" :P "<<b->X<<" "<<b->Y<<endl;

            if (a!=e[v].end() && (a->X)==0)
            {
                c++;
            }

            if (b!=e[v].end() && (b->X)==1)
            {
                c++;
            }

            if (c==2)
            {
                cout<<"No";
                exit(0);
            }
        }
    }
}

void dfs(ll v , ll f)
{
    back_edge[v]=f;

    check[v]=true;

    if (f>=maxf)
    {
        maxf=f;
        floor_g[f].clear();
    }

    floor_g[f].pb(v);
    floor_v[v]=f;

    bool t=false;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i]])
        {
            par[vertex[v][i]]=v;

            dfs(vertex[v][i] , f+1);

            child[v].pb(vertex[v][i]);
        }
        else
        {
            if (!t && vertex[v][i]==par[v])
            {
                t=true;
                continue;
            }

            back_edge[v]=min(back_edge[v] , floor_v[vertex[v][i]]);
        }
    }
}

void ok(ll v)
{
    maxf=0;

    dfs(v , 0);

    for(ll i=maxf;i>0;i--)
    {
        fill_dp(i);
    }
}

void update(ll v)
{
    if (head[head[v]]!=head[v])
    {
        update(head[v]);
    }

    head[v]=head[head[v]];
}

void pre_dsu(ll v , ll u)
{
    update(v);
    update(u);

    if (head[v]==head[u])
    {
        return;
    }

    if (len[head[v]]<len[head[u]])
    {
        head[head[v]]=head[u];
        len[head[u]]+=len[head[v]];
    }
    else
    {
        head[head[u]]=head[v];
        len[head[v]]+=len[head[u]];
    }
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);

    ll n,m,q;
    cin>>n>>m>>q;

    for(ll i=1;i<=n;i++)
    {
        head[i]=i;
        len[i]=1;
    }

    for(ll i=0;i<m;i++)
    {
        ll v,u;
        cin>>v>>u;

        vertex[v].pb(u);
        vertex[u].pb(v);

        pre_dsu(v , u);
    }

    for(ll i=1;i<=n;i++)
    {
        update(i);
    }

    for(ll i=0;i<q;i++)
    {
        ll v,u;
        cin>>v>>u;

        h[v].pb(mp(0 , i));
        h[u].pb(mp(1 , i));

        if (head[v]!=head[u])
        {
            cout<<"No";
            return 0;
        }
    }

    for(ll i=1;i<=n;i++)
    {
        if (!check[i])
        {
            ok(i);
        }
    }

    cout<<"Yes";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) (x & (-x))
#define BIT(a,b) ((ll)(a&(1<<b))==0 ? false : true)

const ll MAXN=2e5+10;
const ll INF=1e12+10;

set <pll> e[MAXN];

vector <pll> h[MAXN];

vector <ll> vertex[MAXN];
vector <ll> floor_g[MAXN];
vector <ll> child[MAXN];

ll dp[MAXN];
ll floor_v[MAXN];
ll back_edge[MAXN];
ll par[MAXN];

bool check[MAXN];

ll maxf=0;

void dsu(ll v , ll u)
{
    if ((ll)(e[v].size())>(ll)(e[u].size()))
    {
        while (!e[u].empty())
        {
            set <pll> :: iterator i=e[u].begin();

            pll a=(*i);
            a.X=1-a.X;

            if (e[v].find(a)!=e[v].end())
            {
                e[v].erase(a);
            }
            else
            {
                e[v].insert(*i);
            }

            e[u].erase(i);
        }
    }
    else
    {
        while (!e[v].empty())
        {
            set <pll> :: iterator i=e[v].begin();

            pll a=(*i);
            a.X=1-a.X;

            if (e[u].find(a)!=e[u].end())
            {
                e[u].erase(a);
            }
            else
            {
                e[u].insert(*i);
            }

            e[v].erase(i);
        }

        e[v].swap(e[u]);
    }
}

void fill_dp(ll f)
{
    for(ll i=0;i<floor_g[f].size();i++)
    {
        ll v=floor_g[f][i];

        for (ll j=0;j<h[v].size();j++)
        {
            e[v].insert(h[v][j]);
        }

        dp[v]=back_edge[v];

        for(ll j=0;j<child[v].size();j++)
        {
            dp[v]=min(dp[v] , dp[child[v][j]]);

            dsu(v , child[v][j]);
        }

        if (f==0 && (ll)(e[v].size())!=0)
        {
            cout<<"No";
            exit(0);
        }

        if (dp[v]>=f)
        {
            //cout<<":D "<<v<<" "<<dp[v]<<" "<<back_edge[v]<<" "<<e[v].size()<<" ";
            ll c=0;

            set <pll> :: iterator a=upper_bound(e[v].begin() , e[v].end() , mp((ll)0 , (ll)(-1)));
            set <pll> :: iterator b=upper_bound(e[v].begin() , e[v].end() , mp((ll)1 , (ll)(-1)));

            //cout<<a->X<<" "<<a->Y<<" :P "<<b->X<<" "<<b->Y<<endl;

            if (a!=e[v].end() && (a->X)==0)
            {
                c++;
            }

            if (b!=e[v].end() && (b->X)==1)
            {
                c++;
            }

            if (c==2)
            {
                cout<<"No";
                exit(0);
            }
        }
    }
}

void dfs(ll v , ll f)
{
    back_edge[v]=f;

    check[v]=true;

    if (f>maxf)
    {
        maxf=f;
        floor_g[f].clear();
    }

    floor_g[f].pb(v);
    floor_v[v]=f;

    bool t=false;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i]])
        {
            par[vertex[v][i]]=v;

            dfs(vertex[v][i] , f+1);

            child[v].pb(vertex[v][i]);
        }
        else
        {
            if (!t && vertex[v][i]==par[v])
            {
                t=true;
                continue;
            }

            back_edge[v]=min(back_edge[v] , floor_v[vertex[v][i]]);
        }
    }
}

void ok(ll v)
{
    maxf=-1;

    dfs(v , 0);

    for(ll i=maxf;i>=0;i--)
    {
        fill_dp(i);
    }
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);

    ll n,m,q;
    cin>>n>>m>>q;

    for(ll i=0;i<m;i++)
    {
        ll v,u;
        cin>>v>>u;

        vertex[v].pb(u);
        vertex[u].pb(v);
    }

    for(ll i=0;i<q;i++)
    {
        ll v,u;
        cin>>v>>u;

        h[v].pb(mp(0 , i));
        h[u].pb(mp(1 , i));
    }

    for(ll i=1;i<=n;i++)
    {
        if (!check[i])
        {
            ok(i);
        }
    }

    cout<<"Yes";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) (x & (-x))
#define BIT(a,b) ((ll)(a&(1<<b))==0 ? false : true)

const ll MAXN=2e5+10;
const ll MAX_LOG=30;
const ll INF=1e12+10;

vector < pair <ll , pll> > h[MAXN];

vector <ll> vertex[MAXN];
vector <ll> floor_g[MAXN];
vector <ll> child[MAXN];

vector <ll> ver;

pll seg[MAXN];

ll par[MAXN][MAX_LOG];

ll state[MAXN][2];

ll dp[MAXN];
ll floor_v[MAXN];
ll back_edge[MAXN];

bool check[MAXN];

ll cnt=0,maxf=0;

bool is_par(ll v , ll u)
{
    if (seg[v].X<=seg[u].X && seg[v].Y>=seg[u].Y)
    {
        return true;
    }

    return false;
}

ll lca(ll v , ll u)
{
    if (is_par(v , u))
    {
        return v;
    }

    if (is_par(u , v))
    {
        return u;
    }

    for(ll i=MAX_LOG-1;i>=0;i--)
    {
        if (!is_par(par[v][i] , u))
        {
            v=par[v][i];
        }
    }

    return par[v][0];
}

void fill_dp(ll f)
{
    for(ll i=0;i<floor_g[f].size();i++)
    {
        ll v=floor_g[f][i];

        for (ll j=0;j<h[v].size();j++)
        {
            state[v][h[v][j].X]=min(state[v][h[v][j].X] , floor_v[lca(h[v][j].Y.X , h[v][j].Y.Y)]);
        }

        dp[v]=back_edge[v];

        for(ll j=0;j<child[v].size();j++)
        {
            dp[v]=min(dp[v] , dp[child[v][j]]);

            state[v][0]=min(state[v][0] , state[child[v][j]][0]);
            state[v][1]=min(state[v][1] , state[child[v][j]][1]);
        }

        cout<<v<<" "<<dp[v]<<" "<<state[v][0]<<" "<<state[v][1]<<endl;

        if (dp[v]>=f)
        {
            if (state[v][0]<f && state[v][1]<f)
            {
                cout<<"No";
                exit(0);
            }
        }
    }
}

void dfs(ll v , ll f)
{
    seg[v].X=cnt++;

    back_edge[v]=f;

    check[v]=true;

    ver.pb(v);

    if (f>maxf)
    {
        maxf=f;
        floor_g[f].clear();
    }

    floor_g[f].pb(v);
    floor_v[v]=f;

    bool t=false;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i]])
        {
            par[vertex[v][i]][0]=v;

            dfs(vertex[v][i] , f+1);

            child[v].pb(vertex[v][i]);
        }
        else
        {
            if (!t && vertex[v][i]==par[v][0])
            {
                t=true;
                continue;
            }

            back_edge[v]=min(back_edge[v] , floor_v[vertex[v][i]]);
        }
    }

    seg[v].Y=cnt++;
}

void ok(ll v)
{
    maxf=-1;
    cnt=0;

    ver.clear();

    dfs(v , 0);

    par[v][0]=v;

    for(ll i=1;i<MAX_LOG;i++)
    {
        for(ll j=0;j<ver.size();j++)
        {
            par[ver[j]][i]=par[par[ver[j]][i-1]][i-1];
        }
    }

    for(ll i=maxf;i>=0;i--)
    {
        fill_dp(i);
    }
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);

    ll n,m,q;
    cin>>n>>m>>q;

    for(ll i=0;i<m;i++)
    {
        ll v,u;
        cin>>v>>u;

        vertex[v].pb(u);
        vertex[u].pb(v);
    }

    for(ll i=0;i<q;i++)
    {
        ll v,u;
        cin>>v>>u;

        h[v].pb(mp(0 , mp(v , u)));
        h[u].pb(mp(1 , mp(v , u)));
    }

    for(ll i=0;i<MAXN;i++)
    {
        state[i][0]=INF;
        state[i][1]=INF;
    }

    for(ll i=1;i<=n;i++)
    {
        if (!check[i])
        {
            ok(i);
        }
    }

    cout<<"Yes";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) (x & (-x))
#define BIT(a,b) ((ll)(a&(1<<b))==0 ? false : true)

const ll MAXN=2e5+10;
const ll INF=1e12+10;

set <pll> e[MAXN];

vector <pll> h[MAXN];

vector <ll> vertex[MAXN];
vector <ll> floor_g[MAXN];
vector <ll> child[MAXN];

ll dp[MAXN];
ll head[MAXN];
ll len[MAXN];
ll floor_v[MAXN];
ll back_edge[MAXN];
ll par[MAXN];

bool check[MAXN];

ll maxf=0;

void dsu(ll v , ll u)
{
    if ((ll)(e[v].size())>(ll)(e[u].size()))
    {
        while (!e[u].empty())
        {
            set <pll> :: iterator i=e[u].begin();

            pll a=(*i);
            a.X=1-a.X;

            if (e[v].find(a)!=e[v].end())
            {
                e[v].erase(a);
            }
            else
            {
                e[v].insert(*i);
            }

            e[u].erase(i);
        }
    }
    else
    {
        while (!e[v].empty())
        {
            set <pll> :: iterator i=e[v].begin();

            pll a=(*i);
            a.X=1-a.X;

            if (e[u].find(a)!=e[u].end())
            {
                e[u].erase(a);
            }
            else
            {
                e[u].insert(*i);
            }

            e[v].erase(i);
        }

        e[v].swap(e[u]);
    }
}

void fill_dp(ll f)
{
    for(ll i=0;i<floor_g[f].size();i++)
    {
        ll v=floor_g[f][i];

        for (ll j=0;j<h[v].size();j++)
        {
            e[v].insert(h[v][j]);
        }

        dp[v]=back_edge[v];

        for(ll j=0;j<child[v].size();j++)
        {
            dp[v]=min(dp[v] , dp[child[v][j]]);

            dsu(v , child[v][j]);
        }

        if (dp[v]>=f)
        {
            //cout<<":D "<<v<<" "<<dp[v]<<" "<<back_edge[v]<<" "<<e[v].size()<<" ";
            ll c=0;

            set <pll> :: iterator a=upper_bound(e[v].begin() , e[v].end() , mp((ll)0 , (ll)(-1)));
            set <pll> :: iterator b=upper_bound(e[v].begin() , e[v].end() , mp((ll)1 , (ll)(-1)));

            //cout<<a->X<<" "<<a->Y<<" :P "<<b->X<<" "<<b->Y<<endl;

            if (a!=e[v].end() && (a->X)==0)
            {
                c++;
            }

            if (b!=e[v].end() && (b->X)==1)
            {
                c++;
            }

            if (c==2)
            {
                cout<<"No";
                exit(0);
            }
        }
    }
}

void dfs(ll v , ll f)
{
    back_edge[v]=f;
    child[v].clear();

    check[v]=true;

    if (f>=maxf)
    {
        maxf=f;
        floor_g[f].clear();
    }

    floor_g[f].pb(v);
    floor_v[v]=f;

    bool t=false;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i]])
        {
            par[vertex[v][i]]=v;

            dfs(vertex[v][i] , f+1);

            child[v].pb(vertex[v][i]);
        }
        else
        {
            if (!t && vertex[v][i]==par[v])
            {
                t=true;
                continue;
            }

            back_edge[v]=min(back_edge[v] , floor_v[vertex[v][i]]);
        }
    }
}

void ok(ll v)
{
    maxf=0;

    dfs(v , 0);

    for(ll i=maxf;i>0;i--)
    {
        fill_dp(i);
    }
}

void update(ll v)
{
    if (head[head[v]]!=head[v])
    {
        update(head[v]);
    }

    head[v]=head[head[v]];
}

void pre_dsu(ll v , ll u)
{
    update(v);
    update(u);

    if (head[v]==head[u])
    {
        return;
    }

    if (len[head[v]]<len[head[u]])
    {
        head[head[v]]=head[u];
        len[head[u]]+=len[head[v]];
    }
    else
    {
        head[head[u]]=head[v];
        len[head[v]]+=len[head[u]];
    }
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);

    ll n,m,q;
    cin>>n>>m>>q;

    for(ll i=1;i<=n;i++)
    {
        head[i]=i;
        len[i]=1;
    }

    for(ll i=0;i<m;i++)
    {
        ll v,u;
        cin>>v>>u;

        vertex[v].pb(u);
        vertex[u].pb(v);

        pre_dsu(v , u);
    }

    for(ll i=0;i<q;i++)
    {
        ll v,u;
        cin>>v>>u;

        h[v].pb(mp(0 , i));
        h[u].pb(mp(1 , i));

        if (head[v]!=head[u])
        {
            cout<<"No";
            return 0;
        }
    }

    for(ll i=1;i<=n;i++)
    {
        if (!check[i])
        {
            ok(i);
        }
    }

    cout<<"Yes";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) (x & (-x))
#define BIT(a,b) ((ll)(a&(1<<b))==0 ? false : true)

const ll MAXN=2e5+10;
const ll INF=1e12+10;

set <pll> e[MAXN];

vector <pll> h[MAXN];

vector <ll> vertex[MAXN];
vector <ll> floor_g[MAXN];
vector <ll> child[MAXN];

ll dp[MAXN];
ll head[MAXN];
ll len[MAXN];
ll floor_v[MAXN];
ll back_edge[MAXN];
ll par[MAXN];

bool check[MAXN];

ll maxf=0;

void dsu(ll v , ll u)
{
    if ((ll)(e[v].size())>(ll)(e[u].size()))
    {
        while (!e[u].empty())
        {
            set <pll> :: iterator i=e[u].begin();

            pll a=(*i);
            a.X=1-a.X;

            if (e[v].find(a)!=e[v].end())
            {
                e[v].erase(a);
            }
            else
            {
                e[v].insert(*i);
            }

            e[u].erase(i);
        }
    }
    else
    {
        while (!e[v].empty())
        {
            set <pll> :: iterator i=e[v].begin();

            pll a=(*i);
            a.X=1-a.X;

            if (e[u].find(a)!=e[u].end())
            {
                e[u].erase(a);
            }
            else
            {
                e[u].insert(*i);
            }

            e[v].erase(i);
        }

        e[v].swap(e[u]);
    }
}

void fill_dp(ll f)
{
    for(ll i=0;i<floor_g[f].size();i++)
    {
        ll v=floor_g[f][i];

        for (ll j=0;j<h[v].size();j++)
        {
            e[v].insert(h[v][j]);
        }

        dp[v]=back_edge[v];

        for(ll j=0;j<child[v].size();j++)
        {
            dp[v]=min(dp[v] , dp[child[v][j]]);

            dsu(v , child[v][j]);
        }

        if (dp[v]>=f)
        {
            //cout<<":D "<<v<<" "<<dp[v]<<" "<<back_edge[v]<<" "<<e[v].size()<<" ";
            ll c=0;

            set <pll> :: iterator a=upper_bound(e[v].begin() , e[v].end() , mp((ll)0 , (ll)(-1)));
            set <pll> :: iterator b=upper_bound(e[v].begin() , e[v].end() , mp((ll)1 , (ll)(-1)));

            //cout<<a->X<<" "<<a->Y<<" :P "<<b->X<<" "<<b->Y<<endl;

            if (a!=e[v].end() && (a->X)==0)
            {
                c++;
            }

            if (b!=e[v].end() && (b->X)==1)
            {
                c++;
            }

            if (c==2)
            {
                cout<<"No";
                exit(0);
            }
        }
    }
}

void dfs(ll v , ll f)
{
    back_edge[v]=f;
    child[v].clear();

    check[v]=true;

    if (f>=maxf)
    {
        maxf=f;
        floor_g[f].clear();
    }

    floor_g[f].pb(v);
    floor_v[v]=f;

    bool t=false;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i]])
        {
            par[vertex[v][i]]=v;

            dfs(vertex[v][i] , f+1);

            child[v].pb(vertex[v][i]);
        }
        else
        {
            if (!t && vertex[v][i]==par[v])
            {
                t=true;
                continue;
            }

            back_edge[v]=min(back_edge[v] , floor_v[vertex[v][i]]);
        }
    }
}

void ok(ll v)
{
    maxf=0;

    dfs(v , 0);

    for(ll i=maxf;i>0;i--)
    {
        fill_dp(i);
    }
}

void update(ll v)
{
    if (head[head[v]]!=head[v])
    {
        update(head[v]);
    }

    head[v]=head[head[v]];
}

void pre_dsu(ll v , ll u)
{
    update(v);
    update(u);

    if (head[v]==head[u])
    {
        return;
    }

    if (len[head[v]]<len[head[u]])
    {
        head[head[v]]=head[u];
        len[head[u]]+=len[head[v]];
    }
    else
    {
        head[head[u]]=head[v];
        len[head[v]]+=len[head[u]];
    }
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);

    ll n,m,q;
    cin>>n>>m>>q;

    for(ll i=1;i<=n;i++)
    {
        head[i]=i;
        len[i]=1;
    }

    for(ll i=0;i<m;i++)
    {
        ll v,u;
        cin>>v>>u;

        vertex[v].pb(u);
        vertex[u].pb(v);

        pre_dsu(v , u);
    }

    for(ll i=1;i<=n;i++)
    {
        update(i);
    }

    for(ll i=0;i<q;i++)
    {
        ll v,u;
        cin>>v>>u;

        h[v].pb(mp(0 , i));
        h[u].pb(mp(1 , i));

        if (head[v]!=head[u])
        {
            cout<<"No";
            return 0;
        }
    }

    for(ll i=1;i<=n;i++)
    {
        if (!check[i])
        {
            ok(i);
        }
    }

    cout<<"Yes";
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) (x & (-x))
#define BIT(a,b) ((ll)(a&(1<<b))==0 ? false : true)

const ll MAXN=2e5+10;
const ll INF=1e12+10;

set <pll> e[MAXN];

vector <pll> h[MAXN];

vector <ll> vertex[MAXN];
vector <ll> floor_g[MAXN];
vector <ll> child[MAXN];

ll dp[MAXN];
ll head[MAXN];
ll len[MAXN];
ll floor_v[MAXN];
ll back_edge[MAXN];
ll par[MAXN];

bool check[MAXN];

ll maxf=0;

void dsu(ll v , ll u)
{
    if ((ll)(e[v].size())>(ll)(e[u].size()))
    {
        while (!e[u].empty())
        {
            set <pll> :: iterator i=e[u].begin();

            pll a=(*i);
            a.X=1-a.X;

            if (e[v].find(a)!=e[v].end())
            {
                e[v].erase(a);
            }
            else
            {
                e[v].insert(*i);
            }

            e[u].erase(i);
        }
    }
    else
    {
        while (!e[v].empty())
        {
            set <pll> :: iterator i=e[v].begin();

            pll a=(*i);
            a.X=1-a.X;

            if (e[u].find(a)!=e[u].end())
            {
                e[u].erase(a);
            }
            else
            {
                e[u].insert(*i);
            }

            e[v].erase(i);
        }

        e[v].swap(e[u]);
    }
}

void fill_dp(ll f)
{
    for(ll i=0;i<floor_g[f].size();i++)
    {
        ll v=floor_g[f][i];

        for (ll j=0;j<h[v].size();j++)
        {
            e[v].insert(h[v][j]);
        }

        dp[v]=back_edge[v];

        for(ll j=0;j<child[v].size();j++)
        {
            dp[v]=min(dp[v] , dp[child[v][j]]);

            dsu(v , child[v][j]);
        }

        if (f==0 && (ll)(e[v].size())!=0)
        {
            cout<<"PNo";
            exit(0);
        }

        if (dp[v]>=f)
        {
            //cout<<":D "<<v<<" "<<dp[v]<<" "<<back_edge[v]<<" "<<e[v].size()<<" ";
            ll c=0;

            set <pll> :: iterator a=upper_bound(e[v].begin() , e[v].end() , mp((ll)0 , (ll)(-1)));
            set <pll> :: iterator b=upper_bound(e[v].begin() , e[v].end() , mp((ll)1 , (ll)(-1)));

            //cout<<a->X<<" "<<a->Y<<" :P "<<b->X<<" "<<b->Y<<endl;

            if (a!=e[v].end() && (a->X)==0)
            {
                c++;
            }

            if (b!=e[v].end() && (b->X)==1)
            {
                c++;
            }

            if (c==2)
            {
                cout<<"No";
                exit(0);
            }
        }
    }
}

void dfs(ll v , ll f)
{
    back_edge[v]=f;

    check[v]=true;

    if (f>maxf)
    {
        maxf=f;
        floor_g[f].clear();
    }

    floor_g[f].pb(v);
    floor_v[v]=f;

    bool t=false;

    for(ll i=0;i<vertex[v].size();i++)
    {
        if (!check[vertex[v][i]])
        {
            par[vertex[v][i]]=v;

            dfs(vertex[v][i] , f+1);

            child[v].pb(vertex[v][i]);
        }
        else
        {
            if (!t && vertex[v][i]==par[v])
            {
                t=true;
                continue;
            }

            back_edge[v]=min(back_edge[v] , floor_v[vertex[v][i]]);
        }
    }
}

void ok(ll v)
{
    maxf=-1;

    dfs(v , 0);

    for(ll i=maxf;i>=0;i--)
    {
        fill_dp(i);
    }
}

void update(ll v)
{
    if (head[head[v]]!=head[v])
    {
        update(head[v]);
    }

    head[v]=head[head[v]];
}

void pre_dsu(ll v , ll u)
{
    update(v);
    update(u);

    if (head[v]==head[u])
    {
        return;
    }

    if (len[head[v]]<len[head[u]])
    {
        head[head[v]]=head[u];
        len[head[u]]+=len[head[v]];
    }
    else
    {
        head[head[u]]=head[v];
        len[head[v]]+=len[head[u]];
    }
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);

    ll n,m,q;
    cin>>n>>m>>q;

    for(ll i=1;i<=n;i++)
    {
        head[i]=i;
        len[i]=1;
    }

    for(ll i=0;i<m;i++)
    {
        ll v,u;
        cin>>v>>u;

        vertex[v].pb(u);
        vertex[u].pb(v);

        pre_dsu(v , u);
    }

    for(ll i=1;i<=n;i++)
    {
        update(i);
    }

    for(ll i=0;i<q;i++)
    {
        ll v,u;
        cin>>v>>u;

        h[v].pb(mp(0 , i));
        h[u].pb(mp(1 , i));

        if (head[v]!=head[u])
        {
            cout<<"No";
            return 0;
        }
    }

    for(ll i=1;i<=n;i++)
    {
        if (!check[i])
        {
            ok(i);
        }
    }

    cout<<"Yes";
}


#include <bits/stdc++.h>

using namespace std;
   bool vis[1005];
int main()
{
    int n;
    pair<int,int>p[1005];
cin>>n;
int ans=0;
for(int i=0;i<n;i++)
{
    cin>>p[i].first>>p[i].second;
    if(p[i].first!=p[i].second)
    {
        vis[p[i].second]=1;
    }

}
for(int i=0;i<n;i++)
{
    if(!vis[p[i].first])
    {
        ans++;
    }
}
cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
   bool vis[1005],v[1005];
    int n,fr[1004];
int main()
{

    pair<int,int>p[1005];
cin>>n;
int ans=0;
for(int i=0;i<n;i++)
{
    cin>>p[i].first>>p[i].second;

}
for(int i=0;i<n;i++)
{
    for(int j=0;j<n;j++)
    {
        if(i!=j&&p[j].first==p[i].second&&!vis[j])
        {
            ans++;
            vis[j]=1;
        }
    }
}
cout<<n-ans<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
using namespace std;
struct bottle{
	int a;
	int b;
	int opened;
};
int main(){
	int n, A, B, count = 0;
	bottle arr[1001];
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> arr[i].a >> arr[i].b;
		arr[i].opened = 0;
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			if (arr[i].b == arr[j].a && i != j){
				arr[j].opened = 1;
			}
		}
		if (arr[n - 1].b == arr[0].a) arr[0].opened = 1;
	}
	for (int i = 0; i < n; i++){
		if (arr[i].opened == 0)
			count++;
	}
	cout << count << endl;
	//system("pause");
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
using namespace std;
struct bottle{
	int a;
	int b;
	int opened;
};
int main(){
	int n, A, B, count = 0;
	bottle arr[1001];
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> arr[i].a >> arr[i].b;
		arr[i].opened = 0;
	}
	for (int i = 1; i <= n; i++){
		if (arr[i].a != arr[i].b){
			for (int j = 1; j <= n; j++){
				if (arr[i].b == arr[j].a){
					arr[j].opened = 1;
				}
			}
		}
	}
	for (int i = 1; i <= n; i++){
		if (arr[i].opened != 1){
			count++;
		}
	}
	cout << count << endl;
	//system("pause");
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;
struct bottle{
	int a;
	int b;
	int opened;
};
int main(){
	int n;
	bottle *arr;
	cin >> n;
	arr = new bottle[n + 1];
	for (int i = 1; i <= n; i++){
		cin >> arr[i].a >> arr[i].b;
		arr[i].opened = 0;
	}
	for (int i = 1; i <= n; i++){
		if (arr[i].a != arr[i].b){
			arr[arr[i].b].opened = 1;
		}
	}
	int count = 0;
	for (int i = 1; i <= n; i++){
		if (arr[i].opened == 0){
			count++;
		}
	}
	cout << count << endl;
	//system("pause");
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
using namespace std;
struct bottle{
	int a;
	int b;
	int opened;
};
int main(){
	int n, A, B, count = 0;
	bottle arr[1001];
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> arr[i].a >> arr[i].b;
		arr[i].opened = 0;
	}
	if (n == 1){
		count = 1;
	}
	else{
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				if (arr[i].b == arr[j].a && i != j){
					arr[j].opened = 1;
				}
			}
			if (arr[n - 1].b == arr[0].a) arr[0].opened = 1;
		}
		for (int i = 0; i < n; i++){
			if (arr[i].opened == 0)
				count++;
		}
	}
	cout << count << endl;
	//system("pause");
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
using namespace std;
struct bottle{
	int a;
	int b;
	int opened;
};
int main(){
	int n, A, B, count = 0;
	bottle arr[1001];
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> arr[i].a >> arr[i].b;
		arr[i].opened = 0;
	}
	for (int i = 1; i <= n; i++){
		//if (arr[i].a != arr[i].b){
			for (int j = 1; j <= n; j++){
				if (arr[i].b == arr[j].a){
					arr[j].opened = 1;
				}
			}
		//}
	}
	for (int i = 1; i <= n; i++){
		if (arr[i].opened != 1){
			count++;
		}
	}
	cout << count << endl;
	//system("pause");
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
using namespace std;
struct bottle{
	int a;
	int b;
	int opened;
};
int main(){
	int n, A, B, count = 0;
	bottle arr[1001];
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> arr[i].a >> arr[i].b;
		arr[i].opened = 0;
	}
	if (n == 1){
		count = 1;
	}
	else{
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				if (arr[i].b == arr[j].a && i != j){
					arr[j].opened = 1;
				}
			}
			if (arr[n - 1].b == arr[0].a) arr[0].opened = 1;
		}
		for (int i = 0; i < n; i++){
			if (arr[i].opened == 0)
				count++;
		}
	}
	cout << count << endl;

	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
using namespace std;
struct bottle{
	int a;
	int b;
	int opened;
};
int main(){
	int n, A, B, count = 0;
	bottle arr[1001];
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> arr[i].a >> arr[i].b;
		arr[i].opened = 0;
	}
	for (int i = 0; i < n; i++){
		for (int j = i + 1; j < n; j++){
			if (arr[i].b == arr[j].a){
				arr[j].opened = 1;
			}
		}
		if (arr[n - 1].b == arr[0].a) arr[0].opened = 1;
	}
	for (int i = 0; i < n; i++){
		if (arr[i].opened == 0)
			count++;
	}
	cout << count << endl;
	//system("pause");
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;
struct bottle{
	int a;
	int b;
	int opened;
};
int main(){
	int n;
	bottle arr[1001];
	cin >> n;
	//arr = new bottle[n + 1];
	for (int i = 1; i <= n; i++){
		cin >> arr[i].a >> arr[i].b;
		arr[i].opened = 0;
	}
	for (int i = 1; i <= n; i++){
		if (arr[i].a != arr[i].b){
			arr[arr[i].b].opened = 1;
		}
	}
	int count = 0;
	for (int i = 1; i <= n; i++){
		if (arr[i].opened == 0){
			count++;
		}
	}
	cout << count << endl;
	//system("pause");
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;
struct bottle{
	int a;
	int b;
	bool opened;
};
int main(){
	int n;
	bottle *arr;
	cin >> n;
	arr = new bottle[n + 1];
	for (int i = 1; i <= n; i++){
		cin >> arr[i].a >> arr[i].b;
	}
	for (int i = 1; i <= n; i++){
		if (arr[i].a != arr[i].b){
			arr[arr[i].b].opened = true;
		}
	}
	int count = 0;
	for (int i = 1; i <= n; i++){
		if (arr[i].opened != true){
			count++;
		}
	}
	cout << count << endl;
	//system("pause");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct brand{
    int n;
    vector<int>o;
};
int main(){
    int n,a,b,j,ans=0;
    cin>>n;
    vector<brand>arr(n);
    for(int i=0;i<n;i++)arr[i].n=0;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        arr[a-1].n++;
        arr[a-1].o.push_back(b-1);

    }
    for(int i=0;i<n;i++)
    if(arr[i].n){
        j=0;
        for(;j<arr[i].o.size();j++)
        if(i==arr[i].o[j]&&arr[i].n>1||i!=arr[i].o[j]&&arr[arr[i].o[j]].n)break;
        if(j==arr[i].o.size())ans++;
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct brand{
    int n;
    vector<int>o;
};
int main(){
    int n,a,b,j,ans=0;
    cin>>n;
    vector<brand>arr(n);
    for(int i=0;i<n;i++)arr[i].n=0;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        arr[a-1].n++;
        arr[a-1].o.push_back(b-1);

    }
    for(int i=0;i<n;i++)
    if(arr[i].n){
        j=0;
        for(;j<arr[i].o.size();j++)
        if(i==arr[i].o[j]&&arr[i].n>1||arr[arr[i].o[j]].n)break;
        if(j==arr[i].o.size())ans++;
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,y;
    cin>>n;
    int a[n];
    vector<vector<int>>t(1000);
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>y;
        t[y-1].push_back(i);

    }
    int ans =0;
    for(int i=0;i<n;i++)
    if(t[a[i]-1].size()==0||t[a[i]-1].size()==1&&
    t[a[i]-1][0]==i)
    ans++;
    cout<<ans;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
struct brand{
    int n;
    vector<int>o;
};
int main(){
    int n,a,b,j,ans=0;
    cin>>n;
    vector<brand>arr(1000);
    for(int i=0;i<n;i++)arr[i].n=0;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        arr[a-1].n++;
        arr[a-1].o.push_back(b-1);

    }
    for(int i=0;i<1000;i++)
    if(arr[i].n){
        j=0;
        for(;j<arr[i].o.size();j++)
        if(i==arr[i].o[j]&&arr[i].n>1||i!=arr[i].o[j]&&arr[arr[i].o[j]].n)break;
        if(j==arr[i].o.size())ans+=arr[i].n;
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,y;
    cin>>n;
    int a[n];
    vector<vector<int>>t(1000);
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>y;
        t[y].push_back(i);

    }
    int ans =0;
    for(int i=0;i<n;i++)
    if(t[a[i]-1].size()==0||t[a[i]-1].size()==1&&
    t[a[i]-1][0]==i)
    ans++;
    cout<<ans;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
struct brand{
    int n;
    vector<int>o;
};
int main(){
    int n,a,b,j,ans=0;
    cin>>n;
    vector<brand>arr(1000);
    for(int i=0;i<n;i++)arr[i].n=0;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        arr[a-1].n++;
        arr[b-1].o.push_back(a-1);

    }
    for(int i=0;i<1000;i++)
    if(arr[i].n){
        j=0;
        for(;j<arr[i].o.size();j++)
        if(i==arr[i].o[j]&&arr[i].n>1||i!=arr[i].o[j]&&arr[arr[i].o[j]].n)break;
        if(j==arr[i].o.size())ans+=arr[i].n;
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct brand{
    int n;
    vector<int>o;
};
int main(){
    int n,a,b,j,ans=0;
    cin>>n;
    vector<brand>arr(n);
    for(int i=0;i<n;i++)arr[i].n=0;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        arr[a-1].n++;
        arr[a-1].push_back(b-1);

    }
    for(int i=0;i<n;i++)
    if(arr[i].n){
        j=0;
        for(;j<arr[i].o.size();j++)
        if(i==arr[i].o[j]&&arr[i].n>1||arr[arr[i].o[j]].n)break;
        if(j==arr[i].o.size())ans++;
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct brand{
    int n;
    vector<int>o;
};
int main(){
    int n,a,b,j,ans=0;
    cin>>n;
    vector<brand>arr(1000);
    for(int i=0;i<n;i++)arr[i].n=0;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        arr[a-1].n++;
        arr[a-1].o.push_back(b-1);

    }
    for(int i=0;i<1000;i++)
    if(arr[i].n){
        j=0;
        for(;j<arr[i].o.size();j++)
        if(i==arr[i].o[j]&&arr[i].n>1||i!=arr[i].o[j]&&arr[arr[i].o[j]].n)break;
        if(j==arr[i].o.size())ans++;
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    static int count=0,a[1000],x,y;
    for(int i=0;i<n;i++)
    {
        cin>>x>>y;
        a[y-1]++;
    }
    for(int i=0;i<1000;i++)
    {
        if(a[i]>0) count++;
    }
    cout<<2*n-count;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,count=0;
    cin>>n;
    vector<int>s(n);
    vector<int> s2(n);
    vector<int> s3(n);
    for(int i=0;i<n;i++)
    {
        cin>>s[i]>>s2[i];

    }
    for(int t=0;t<n;t++)
    {
        for(int u=0;u<n;u++)
        {
            if(s[t]==s2[u]&&t!=u) {s3[t]++;break;}

        }
    }
    cout<<s3.count(0);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b;
    cin>>n;
    vector<int>s(n);
    vector<int> s2(n);
    vector<int> s3(n);
    for(int i=0;i<n;i++)
    {
        cin>>s[i]>>s2[i];

    }
    for(int t=0;t<n;t++)
    {
        for(int u=0;u<n;u++)
        {
            if(s[t]==s2[u]&&t!=u) {s3[t]++;break;}

        }
    }
    cout<<count(s3.begin(),s3.end(),0);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,count=0;
    cin>>n;
    vector<int>s(n);
    vector<int> s2(n);
    vector<int> s3(n);
    for(int i=0;i<n;i++)
    {
        cin>>s[i]>>s2[i];

    }
    for(int t=0;t<n;t++)
    {
        for(int u=0;u<n;u++)
        {
            if(s[t]==s2[u]&&t!=u) {s3[t]++;break;}

        }
    }
    cout<<count(s3.begin(),s3.end(),0);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,count=0;
    cin>>n;
    vector<int>s;
    vector<int> s2;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        s.insert(a);

        s2.insert(b);
    }
    for(int t=0;t<n;t++)
    {
        for(int u=0;u<n;u++)
        {
            if(s[t]==s2[u]&&t!=u) count++;

        }
    }
    cout<<n-count;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,count=0;
    cin>>n;
    vector<int>s;
    vector<int> s2;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        s[i]=(a);

        s2[i]=(b);
    }
    for(int t=0;t<n;t++)
    {
        for(int u=0;u<n;u++)
        {
            if(s[t]==s2[u]&&t!=u) count++;

        }
    }
    cout<<n-count;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,count=0;
    cin>>n;
    vector<int>s(n);
    vector<int> s2(n);
    for(int i=0;i<n;i++)
    {
        cin>>s[i]>>s2[i];

    }
    for(int t=0;t<n;t++)
    {
        for(int u=0;u<n;u++)
        {
            if(s[t]==s2[u]&&t!=u) count++;

        }
    }
    cout<<n-count;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define lld long double
#define fl float
#define pii pair<int,int>
#define INF INT_MAX
#define M 100001
#define pb(x) push_back(x)
#define fr(i, n) for (int i=0 ; i<n ; i++)
#define fri(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define optimize ios_base::sync_with_stdio(0), cin.tie(0)

using namespace std;
int main(){

    int n;
    cin >> n;
    int a[n], b[n], ch[1001] = {0}, cnt = 0, occur[1001] = {0};
    fr(i, n) {
    	cin >> a[i] >> b[i];
    	if(a[i] == b[i])
    	    if(occur[a[i]] == 0) cnt++; ch[b[i]]--, occur[a[i]]++;
    	ch[b[i]]++;
    }
    if(cnt == n) {cout << n; return 0;}
    int ans = 0;
    fr(i, n)
    	if(ch[a[i]] <= 0 && occur[a[i]] <= 1) ans++;
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define lld long double
#define fl float
#define pii pair<int,int>
#define INF INT_MAX
#define M 100001
#define pb(x) push_back(x)
#define fr(i, n) for (int i=0 ; i<n ; i++)
#define fri(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define optimize ios_base::sync_with_stdio(0), cin.tie(0)

using namespace std;
int main(){

    int n;
    cin >> n;
    int a[n], b[n], ch[1001] = {0}, cnt = 0;
    fr(i, n) {
    	cin >> a[i] >> b[i];
    	if(a[i] == b[i]) cnt++, ch[b[i]]--;
    	ch[b[i]]++;
    }
    if(cnt == n) {cout << n; return 0;}
    int ans = 0;
    fr(i, n)
    	if(ch[a[i]] <= 0) ans++;
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define lld long double
#define fl float
#define pii pair<int,int>
#define INF INT_MAX
#define M 100001
#define pb(x) push_back(x)
#define fr(i, n) for (int i=0 ; i<n ; i++)
#define fri(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define optimize ios_base::sync_with_stdio(0), cin.tie(0)

using namespace std;
int main(){

    int n;
    cin >> n;
    int a[n], b[n], ch[1001] = {0}, cnt = 0;
    fr(i, n) {
    	cin >> a[i] >> b[i];
    	if(a[i] == b[i]) cnt++;
    	ch[b[i]]++;
    }
    if(cnt == n) {cout << n; return 0;}
    int ans = 0;
    fr(i, n)
    	if(!ch[a[i]]) ans++;
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define lld long double
#define fl float
#define pii pair<int,int>
#define INF INT_MAX
#define M 100001
#define pb(x) push_back(x)
#define fr(i, n) for (int i=0 ; i<n ; i++)
#define fri(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define optimize ios_base::sync_with_stdio(0), cin.tie(0)
#define MOD 1000000007

using namespace std;

ll modular(ll base, ll exp, ll mod)
{
    ll x = 1;
    ll i;
    ll power = base % mod;

    for (i = 0; i < sizeof(ll) * 8; i++) {
        ll least_sig_bit = 0x00000001 & (exp >> i);
        if (least_sig_bit)
            x = (x * power) % mod;
        power = (power * power) % mod;
    }

    return x;
}

int main(){
	optimize;
	int n;
	cin >> n;
	int a[n], b[n];
	fr(i, n) cin >> a[i] >> b[i];
	int cnt = 0;
	fr(i, n){
		fr(j, n){
			if(i == j) continue;
			if(a[i] == b[j]) {cnt++; break;}
		}
	}
	cout << n - cnt;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define lld long double
#define fl float
#define pii pair<int,int>
#define INF INT_MAX
#define M 100001
#define pb(x) push_back(x)
#define fr(i, n) for (int i=0 ; i<n ; i++)
#define fri(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define optimize ios_base::sync_with_stdio(0), cin.tie(0)
#define MOD 1000000007

using namespace std;

ll modular(ll base, ll exp, ll mod)
{
    ll x = 1;
    ll i;
    ll power = base % mod;

    for (i = 0; i < sizeof(ll) * 8; i++) {
        ll least_sig_bit = 0x00000001 & (exp >> i);
        if (least_sig_bit)
            x = (x * power) % mod;
        power = (power * power) % mod;
    }

    return x;
}

int main(){
	int n;
	cin >> n;
	vector<int> a, b, done, check;
	int ch[1001];
	int var1, var2, cnt = 0;
	fr(i, n){
		cin >> var1;
		a.pb(var1);
		check.pb(var1);
		ch[var1]++;
		cin >> var2;
		b.pb(var2);
		if(!ch[var2]) check.pb(var2);
		if(var1 == var2) cnt++;
	}
	if(cnt == check.size()) cout << cnt;
	else{
		set_difference(check.begin(), check.end(), b.begin(), b.end(), inserter(done, done.begin()));
		cout << done.size();
	}
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define lld long double
#define fl float
#define pii pair<int,int>
#define INF INT_MAX
#define M 100001
#define pb(x) push_back(x)
#define fr(i, n) for (int i=0 ; i<n ; i++)
#define fri(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define optimize ios_base::sync_with_stdio(0), cin.tie(0)
#define MOD 1000000007

using namespace std;

ll modular(ll base, ll exp, ll mod)
{
    ll x = 1;
    ll i;
    ll power = base % mod;

    for (i = 0; i < sizeof(ll) * 8; i++) {
        ll least_sig_bit = 0x00000001 & (exp >> i);
        if (least_sig_bit)
            x = (x * power) % mod;
        power = (power * power) % mod;
    }

    return x;
}

int main(){
	int n;
	cin >> n;
	set<int> a, b, done, check;
	int var1, var2, cnt = 0;
	fr(i, n){
		cin >> var1;
		a.insert(var1);
		check.insert(var1);
		cin >> var2;
		b.insert(var2);
		check.insert(var2);
		if(var1 == var2) cnt++;
	}
	if(cnt == check.size()) cout << cnt;
	else{
		set_difference(check.begin(), check.end(), b.begin(), b.end(), inserter(done, done.begin()));
		cout << done.size();
	}
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define lld long double
#define fl float
#define pii pair<int,int>
#define INF INT_MAX
#define M 100001
#define pb(x) push_back(x)
#define fr(i, n) for (int i=0 ; i<n ; i++)
#define fri(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define optimize ios_base::sync_with_stdio(0), cin.tie(0)
#define MOD 1000000007

using namespace std;

ll modular(ll base, ll exp, ll mod)
{
    ll x = 1;
    ll i;
    ll power = base % mod;

    for (i = 0; i < sizeof(ll) * 8; i++) {
        ll least_sig_bit = 0x00000001 & (exp >> i);
        if (least_sig_bit)
            x = (x * power) % mod;
        power = (power * power) % mod;
    }

    return x;
}

int main(){
	optimize;
	int n;
	cin >> n;
	int a[n], b[n], occur[1001] = {0}, cbo[1001] = {0};
	fr(i, n){
		cin >> a[i] >> b[i];
		if(a[i] == b[i] && !occur[a[i]]){
			occur[a[i]]++;
			continue;
		}
		cbo[b[i]]++;
	}
	int ans = 0, done[1001] = {0};
	fr(i, n) {
	    if(!cbo[a[i]] && !done[a[i]]) ans++;
	    done[a[i]]++;
	}
	cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define lld long double
#define fl float
#define pii pair<int,int>
#define INF INT_MAX
#define M 100001
#define pb(x) push_back(x)
#define fr(i, n) for (int i=0 ; i<n ; i++)
#define fri(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define optimize ios_base::sync_with_stdio(0), cin.tie(0)
#define MOD 1000000007

using namespace std;

ll modular(ll base, ll exp, ll mod)
{
    ll x = 1;
    ll i;
    ll power = base % mod;

    for (i = 0; i < sizeof(ll) * 8; i++) {
        ll least_sig_bit = 0x00000001 & (exp >> i);
        if (least_sig_bit)
            x = (x * power) % mod;
        power = (power * power) % mod;
    }

    return x;
}

int main(){
	optimize;
	int n;
	cin >> n;
	int a[n], b[n], occur[1001] = {0}, cbo[1001] = {0};
	fr(i, n){
		cin >> a[i] >> b[i];
		if(a[i] == b[i] && !occur[a[i]]){
			occur[a[i]]++;
			continue;
		}
		cbo[b[i]]++;
	}
	int ans = 0;
	fr(i, n) if(!cbo[a[i]]) ans++;
	cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define lld long double
#define fl float
#define pii pair<int,int>
#define INF INT_MAX
#define M 100001
#define pb(x) push_back(x)
#define fr(i, n) for (int i=0 ; i<n ; i++)
#define fri(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define optimize ios_base::sync_with_stdio(0), cin.tie(0)

using namespace std;
int main(){

    int n;
    cin >> n;
    int a[n], b[n], ch[1001] = {0}, cnt = 0, occur[1001] = {0};
    fr(i, n) {
    	cin >> a[i] >> b[i];
    	if(a[i] == b[i]){
    	    if(occur[a[i]] == 0) cnt++;
    	    ch[b[i]]--, occur[a[i]]++;
    	}
    	ch[b[i]]++;
    }
    if(cnt == n) {cout << n; return 0;}
    int ans = 0;
    fr(i, n)
    	if(ch[a[i]] <= 0 && occur[a[i]] <= 1) ans++;
    cout << ans;
    return 0;
}


/*All Knights must bleed Jaime, Blood is the seal of our devotion */
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;

map<ll, vector<ll> > G;
ll visi[1000];
ll dfs(ll s){
    if(visi[s] == 1)
        return 0;
    visi[s] = 1;
    ll ans = 1;
    for(auto z : G[s])
        ans += dfs(z);
    return ans;
}

int main(){
ios_base::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
    ll n;
    cin>>n;
    for(ll i=0;i<n;i++){
        ll u,v;
        cin>>u>>v;
        G[u].push_back(v);
    }
    ll ans = 0;
    for(ll i=1;i<=n;i++)
        if(visi[i] == 0 && dfs(i) == 1)
            ans++;
    cout<<ans;

    return 0;
}


/*All Knights must bleed Jaime, Blood is the seal of our devotion */
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main(){
ios_base::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
    ll n;
    cin>>n;
    vector<pair<ll,ll> > g;
    set<ll> s;
    for(ll i=0;i<n;i++){
        ll u,v;
        cin>>u>>v;
        g.push_back({u,v});
    }
    for(auto z : g)
        s.insert(z.first), s.insert(z.second);
    for(auto z : g)
        if(z.first != z.second)
            s.erase(z.second);
    cout<<s.size()<<endl;

    return 0;
}


/*All Knights must bleed Jaime, Blood is the seal of our devotion */
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;

map<ll, vector<ll> > G;
int main(){
ios_base::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
    ll n;
    cin>>n;
    multiset<ll> vert;
    for(ll i=0;i<n;i++){
        ll u,v;
        cin>>u>>v;

        if(u!=v)
            G[v].push_back(u);
        vert.insert(u);
        //vert.insert(v);
    }
    ll ans = 0;
    for(auto z : vert)
        if(G[z].size()==0)
            ans++;
    cout<<ans;

    return 0;
}


#include <bits/stdc++.h>

typedef long long int ll;

using namespace std;

int main(){
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r+", stdin);
        freopen("out.txt", "w+", stdout);
    #endif
    ll q, _q;
    cin>>q;
    _q = q;
    map<ll,ll> bot;
    vector<pair<ll,ll> > arr;
    while(q--){
        ll u, v;
        cin>>u>>v;
        bot[u] = bot[u] + 1;
        arr.push_back({u,v});
    }

    ll ans = 0;
    for(auto z : arr){
        if(z.first != z.second && bot[z.second] > 0)
            ans++;
        else if(z.first == z.second && bot[z.second] > 1)
            ans++;
    }

    cout<<_q-ans;

    return 0;
}


/*All Knights must bleed Jaime, Blood is the seal of our devotion */
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main(){
ios_base::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
    ll n;
    cin>>n;
    vector<pair<ll,ll> > g;
    multiset<ll> s;
    for(ll i=0;i<n;i++){
        ll u,v;
        cin>>u>>v;
        g.push_back({u,v});
    }
    for(auto z : g)
        s.insert(z.first), s.insert(z.second);
    for(auto z : g)
        if(z.first != z.second)
            s.erase(z.second);
    cout<<s.size()<<endl;

    return 0;
}


    #include<iostream>
    using namespace std;
    int i,n,j,ans,a[105],b[105];
    int main(){
    	cin>>n;
    	while(i<n){
    		cin>>a[i]>>b[i]; i++;
    	}
    	for(i=0;i<n;i++){
    		for(j=0;j<n;j++){
    			if(a[i]==b[j]&&i!=j){ans++;break;}

    		}
    	}cout<<n-ans;
    }


/*All Knights must bleed Jaime, Blood is the seal of our devotion */
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;

map<ll, vector<ll> > G;
int main(){
ios_base::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
    ll n;
    cin>>n;
    set<ll> vert;
    for(ll i=0;i<n;i++){
        ll u,v;
        cin>>u>>v;

        if(u!=v)
        G[v].push_back(u);
        vert.insert(u);
        vert.insert(v);
    }
    ll ans = 0;
    for(auto z : vert)
        if(G[z].size()==0)
            ans++;
    cout<<ans;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int maxn = 3e5+10;
int n;
bool marked[maxn];
int ans;

int main(){
	cin >> n;
	int a[n];
	int b[n];
	int ans = 0;
	for(int i = 0; i<n; i++){
		cin >> a[i] >> b[i];
	}
	for(int i = 0; i<n; i++){
		if(a[i]!=b[i]){
			marked[b[i]]=true;
		}
	}
	for(int i = 1; i<n+1; i++){
		if(marked[i]==true){
			ans++;
		}
	}
	cout << n-ans << endl;
}


#include<bits/stdc++.h>

using namespace std;

const int maxn=2e5+10;
int n;
bool marked[maxn];

int main(){
	cin >> n;
	int a[n];
	int b[n];
	int ans = 0;
	for(int i = 0; i<n; i++){
		cin >> a[i] >> b[i];
	}
	for(int i = 0; i<n; i++){
		if(a[i]!=b[i] && marked[b[i]]!=true){
			marked[b[i]] = true;
			ans ++;
		}
	}
	cout << n-ans << endl;

}


#include<bits/stdc++.h>

using namespace std;

const int maxn = 3e5+10;
int n,ans,sum;
bool marked[maxn];

int main(){
	cin >> n;
	int a[n];
	int b[n];
	int c[n];
	int ans = 0;
	for(int i = 0; i<n; i++){
		cin >> a[i] >> b[i];
		c[i] = a[i];
	}

	for(int i = 0; i<n; i++){
		if(a[i]!=b[i]){
			marked[b[i]]=true;
		}
		else{
			bool l = false;
			for(int j = i+1; j<n; j++){
				if(a[j]==a[i] && b[j]==a[j]){
					marked[a[i]]=true;
					break;
				}
			}
		}
	}
	for(int i = 0; i<n; i++){
		if(a[i]==b[i] && marked[a[i]]==false){
			marked[a[i]]=true;
			sum++;
		}
	}
	for(int i = 0; i<n; i++){
		if(marked[a[i]]==false){
			ans++;
		}
	}
	cout << ans+sum << endl;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
	int n;
	cin >> n;
	int a[n];
	int b[n];
	bool marked[n];
	for(int i = 0; i<n; i++){
		marked[i] = false;
	}
	int ans = 0;
	for(int i = 0; i<n; i++){
		cin >> a[i] >> b[i];
	}
	for(int i = 0; i<n; i++){
		if(a[i]!=b[i] && marked[b[i]]!=true){
			marked[b[i]] = true;
			ans ++;
		}
	}
	cout << n-ans << endl;

}


#include<bits/stdc++.h>

using namespace std;

const int maxn = 3e5+10;
int n;
bool marked[maxn];
int ans;

int main(){
	cin >> n;
	int a[n];
	int b[n];
	int ans = 0;
	for(int i = 0; i<n; i++){
		cin >> a[i] >> b[i];
	}

	for(int i = 0; i<n; i++){
		if(a[i]!=b[i]){
			marked[b[i]]=true;
		}
		else{
			for(int j = i+1; j<n; j++){
				if(a[j]==a[i] && b[j]==a[j]){
					marked[a[i]]=true;
					break;
				}
			}
		}
	}
	for(int i = 0; i<n; i++){
		if(marked[a[i]]==false){
			ans++;
		}
	}
	cout << ans << endl;
}


#include<bits/stdc++.h>

using namespace std;

const int maxn = 3e5+10;
int n;
bool marked[maxn];
int ans;

int main(){
	cin >> n;
	int a[n];
	int b[n];
	int ans = 0;
	for(int i = 0; i<n; i++){
		cin >> a[i] >> b[i];
	}
	for(int i = 0; i<n; i++){
		if(a[i]!=b[i]){
			marked[b[i]]=true;
		}
	}
	for(int i = 0; i<n; i++){
		if(marked[a[i]]==false){
			ans++;
		}
	}
	cout << ans << endl;
}


#include<bits/stdc++.h>

using namespace std;
int main(){
	int n;
	cin >> n;
	int a[n];
	int b[n];
	bool marked[n];
	int ans = 0;
	for(int i = 0; i<n; i++){
		cin >> a[i] >> b[i];
	}
	for(int i = 0; i<n; i++){
		if(a[i]!=b[i] && marked[b[i]]!=true){
			marked[b[i]] = true;
			ans ++;
		}
	}
	cout << n-ans << endl;

}


#include<bits/stdc++.h>

using namespace std;

const int maxn=2e5+10;
int n;
bool marked[maxn];

int main(){
	cin >> n;
	int a[n];
	int b[n];
	int ans = 0;
	for(int i = 0; i<n; i++){
		cin >> a[i] >> b[i];
	}
	for(int i = 0; i<n; i++){
		if(a[i]!=b[i] && marked[b[i]]!=true){
			marked[b[i]] = true;
		}
	}
	for(int i = 0; i<n; i++){
		if(marked[b[i]]!=false){
			ans++;
		}
	}
	cout << ans << endl;

}


#include<bits/stdc++.h>
const int M=300000;//M=1e6+100;
typedef long long int ll;
using namespace std;

ll n,i,j,t,cnt(0),d,x,y,ans(0),m,k(0);

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>n;
	ll a[1001]={0},time[1001]={0};
	ll xx[200],yy[200];
	for(i=0;i<n;i++)
	{
		cin>>xx[i]>>yy[i];
		time[xx[i]]++;
		if(time[xx[i]]>1)
		{
			ans-=2;
			time[xx[i]]-=2;
		}
		if(xx[i]!=yy[i])
		{
			a[yy[i]]++;
		}
	}
	for(i=0;i<n;i++)
	{
		if(a[xx[i]]>0)
		{
			//cout<<a[xx[i]]<<endl;
			a[xx[i]]--;
		}else
		{
			ans++;
		}
	}
	cout<<ans;

}


#include<bits/stdc++.h>
const int M=300000;//M=1e6+100;
typedef long long int ll;
using namespace std;

ll n,i,j,t,cnt(0),d,x,y,ans(0),m,k(0);

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>n;
	ll a[1001]={0};
	ll xx[200],yy[200];
	for(i=0;i<n;i++)
	{
		cin>>xx[i]>>yy[i];
		if(xx[i]!=yy[i])
		{
			a[yy[i]]=-1;
		}
	}
	for(i=0;i<n;i++)
	{
		if(a[xx[i]]!=-1)
		{
			ans++;
		}
	}
	cout<<ans;

}


#include<bits/stdc++.h>
const int M=300000;//M=1e6+100;
typedef long long int ll;
using namespace std;

ll n,i,j,t,cnt(0),d,x,y,ans(0),m,k(0);

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>n;
	ll a[1001]={0};
	ll xx[200],yy[200];
	for(i=0;i<n;i++)
	{
		cin>>xx[i]>>yy[i];
		if(xx[i]!=yy[i])
		{
			a[yy[i]]=-1;
		}
	}
	for(i=0;i<n;i++)
	{
		if(a[xx[i]]<0)
		{
			ans++;
		}
	}
	cout<<ans;

}


#include<bits/stdc++.h>
const int M=300000;//M=1e6+100;
typedef long long int ll;
using namespace std;

ll n,i,j,t,cnt(0),d,x,y,ans(0),m,k(0);

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>n;
	ll a[1001]={0};
	ll xx[200],yy[200];
	for(i=0;i<n;i++)
	{
		cin>>xx[i]>>yy[i];
		if(xx[i]!=yy[i])
		{
			a[yy[i]]=-1;
		}
	}
	for(i=0;i<n;i++)
	{
		if(a[xx[i]]==-1)
		{
			ans++;
		}
	}
	cout<<ans;

}


#include<bits/stdc++.h>
const int M=300000;//M=1e6+100;
typedef long long int ll;
using namespace std;

ll n,i,j,t,cnt(0),d,x,y,ans(0),m,k(0);

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>n;
	ll a[1001]={0},time[1001]={0};
	ll xx[200],yy[200];
	for(i=0;i<n;i++)
	{
		cin>>xx[i]>>yy[i];
		time[yy[i]]++;
		if(time[yy[i]]>1)
		{
			ans-=2;
			time[yy[i]]-=2;
		}
		if(xx[i]!=yy[i])
		{
			a[yy[i]]++;
		}
	}
	for(i=0;i<n;i++)
	{
		if(a[xx[i]]>0)
		{
			//cout<<a[xx[i]]<<endl;
			a[xx[i]]--;
		}else
		{
			ans++;
		}
	}
	cout<<ans;

}


#include<bits/stdc++.h>
const int M=300000;//M=1e6+100;
typedef long long int ll;
using namespace std;

ll n,i,j,t,cnt(0),d,x,y,ans(0),m,k(0);

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>n;
	ll a[n],b[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(i!=j && a[i]==b[j])
			{
				ans++;
				break;
			}
		}
	}
	cout<<n-ans;

}


#include<bits/stdc++.h>
const int M=300000;//M=1e6+100;
typedef long long int ll;
using namespace std;

ll n,i,j,t,cnt(0),d,x,y,ans(0),m,k(0);

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>n;
	ll a[200]={0};
	ll xx[200],yy[200];
	for(i=0;i<n;i++)
	{
		cin>>xx[i]>>yy[i];
		if(xx[i]!=yy[i])
		{
			a[yy[i]]=-1;
		}
	}
	for(i=0;i<n;i++)
	{
		if(a[xx[i]]!=-1)
		{
			ans++;
		}
	}
	cout<<ans;

}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
const ll mod = 1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N;
    cin >> N;
    int cnt =0 ;
    unordered_map<int, int> frq;
    unordered_map<int,vector<int>> key;
    int A[N];
    rep(i, 0, N)
    {
        int a,b;
        cin >> a >> b;
        A[i] = a;
        frq[a]++;
        key[b].pb(a);
    }

    for(int i = 0; i < N; ++i)
    {
        for(auto val : key[A[i]])
        {
            if(A[i] == val)
                continue;
            else if(frq[val])
                cnt++;
        }
    }

    cout << N-cnt  << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

using ll = long long int;

int N;
int A[102];
unordered_map<int,vector<int>> M;

bool check(int a,int b)
{
    if(a == b)
        return false;
    else
    {
        auto itr = find(M[a].begin(),M[a].end(),b);
        if(itr == M[a].end())
            return false;
        else
            return true;
    }
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> N;
    for(int i = 0; i < N; ++i)
    {
        int a,b;
        cin >> a >> b;
        A[i] = a;
        if(a != b)
            M[b].push_back(a);
    }
    int cnt = 0;
    for(int i = 0; i < N; ++i)
    {
        for(int j = 0; j < N; ++j)
        {
            if(check(A[i], A[j]))
            {
                cnt++;
                break;
            }
        }
    }

    cout << N - cnt << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
const ll mod = 1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N;
    cin >> N;
    int cnt =0 ;
    unordered_map<int, int> frq;
    unordered_map<int,vector<int>> key;
    int A[N];
    rep(i, 0, N)
    {
        int a,b;
        cin >> a >> b;
        A[i] = a;
        frq[a]++;
        key[b].pb(a);
    }

    for(int i = 0; i < N; ++i)
    {
        for(auto val : key[A[i]])
        {
            if(A[i] == val)
                continue;
            else if(frq[val])
            {
                cnt++;
                break;
            }
        }
    }

    cout << N-cnt  << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

using ll = long long int;

int N;
int A[102];
unordered_map<int,vector<int>> M;
unordered_map<int, int> freq;
bool check(int a,int b)
{

    auto itr = find(M[a].begin(),M[a].end(),b);
    if(itr == M[a].end())
        return false;
    else
        return true;

}
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> N;
    for(int i = 0; i < N; ++i)
    {
        int a,b;
        cin >> a >> b;
        freq[a]++;
        A[i] = a;
        M[b].push_back(a);
    }
    int cnt = 0;
    for(int i = 0; i < N; ++i)
    {
        for(int j = 0; j < N; ++j)
        {
            if(i == j)
                continue;
            if(check(A[i], A[j]))
            {
                cnt++;
                break;
            }
        }
    }

    cout << N - cnt << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
const ll mod = 1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N;
    cin >> N;
    int cnt =0 ;
    unordered_map<int, int> frq,key;
    int A[N];
    rep(i, 0, N)
    {
        int a,b;
        cin >> a >> b;
        A[i] = a;
        frq[a]++;
        key[b] = a;
    }

    for(int i = 0; i < N; ++i)
    {
        if(key[A[i]]!=A[i] && frq[key[A[i]]])
            cnt++;
    }
    cout << N-cnt  << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

using ll = long long int;

int N;
int A[102];
unordered_map<int,vector<int>> M;
unordered_map<int, int> freq;
bool check(int a,int b)
{
    if(a == b)
    {
        if(freq[a]>1)
            return true;
        else
            return false;

    }
    auto itr = find(M[a].begin(),M[a].end(),b);
    if(itr == M[a].end())
        return false;
    else
        return true;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> N;
    for(int i = 0; i < N; ++i)
    {
        int a,b;
        cin >> a >> b;
        freq[a]++;
        A[i] = a;
        if(a != b)
            M[b].push_back(a);
    }
    int cnt = 0;
    for(int i = 0; i < N; ++i)
    {
        for(int j = 0; j < N; ++j)
        {
            if(check(A[i], A[j]))
            {
                cnt++;
                break;
            }
        }
    }

    cout << N - cnt << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

using ll = long long int;
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N;
    cin >> N;
    vector<bool> locked(N,true);
    vector<pair<int,int>> V(N);
    for(int i = 0; i < N; ++i)
        cin >> V[i].first >> V[i].second;
    int cnt = 0;
    for(int i = 0; i < N; ++i)
    {
        for(int j = 0; j < N; ++j)
        {
            if(i==j)
                continue;
            else if(V[i].second == V[j].first && locked[j])
            {
                locked[j] = false;
                cnt++;
            }
        }
    }
    cout << N - cnt << '\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,j,x,y,k,s1=0;bool hi;
  cin>>n; set<int> s;map<int,vector<int> > m;
  for(i=1;i<=n;i++)
   {
     cin>>x>>y;
    s.insert(y);
   m[y].push_back(x);
  }
 for(auto it=m.begin();it!=m.end();it++)
  {k=(it->first); hi=false;
    for(j=0;j<(it->second).size();j++)
    {int l=m[k][j];
     if(k==l){if(m[k].size()==1) s1++;
       continue; }
      if((s.find(l)==s.end()))
       s1++;
    }
  }
 cout<<s1;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,j,x,y,s=0;
  cin>>n;
  for(i=1;i<=n;i++)
   {
     cin>>x>>y;
    if(x==y) s++;
  }
 cout<<s;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,j,x,y,s1=0;bool hi;
  cin>>n; set<int> s;map<int,vector<int> > m;
  for(i=1;i<=n;i++)
   {
     cin>>x>>y;
    s.insert(x);
   m[x].push_back(y);
  }
 for(auto it=m.begin();it!=m.end();it++)
  {k=(it->first); hi=false;
    for(j=0;j<(it->second).size();j++)
    {int l=m[k][j];
      if(k!=l&&(s.find(l)!=s.end()))
        {hi=true; break; }
    }
   if(!hi) s1++;
  }
 cout<<s1;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,j,x,y,k,s1=0;bool hi;
  cin>>n; set<int> s;map<int,vector<int> > m;
  for(i=1;i<=n;i++)
   {
     cin>>x>>y;
    s.insert(y);
   m[y].push_back(x);
  }
 for(auto it=m.begin();it!=m.end();it++)
  {k=(it->first); hi=false;
    for(j=0;j<(it->second).size();j++)
    {int l=m[k][j];
      if(k!=l&&(s.find(l)!=s.end()))
        {hi=true; break; }
    }
   if(!hi) s1+=m[k].size();
  }
 cout<<s1;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,j,x,y,k,s1=0;bool hi;
  cin>>n; set<int> s;map<int,vector<int> > m;
  for(i=1;i<=n;i++)
   {
     cin>>x>>y;
    s.insert(x);
   m[x].push_back(y);
  }
 for(auto it=m.begin();it!=m.end();it++)
  {k=(it->first); hi=false;
    for(j=0;j<(it->second).size();j++)
    {int l=m[k][j];
      if(k!=l&&(s.find(l)!=s.end()))
        {hi=true; break; }
    }
   if(!hi) s1+=m[k].size();
  }
 cout<<s1;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,j,x,y,k,s1=0;bool hi;
  cin>>n; set<int> s;map<int,vector<int> > m;
  for(i=1;i<=n;i++)
   {
     cin>>x>>y;
    s.insert(x);
   m[x].push_back(y);
  }
 for(auto it=m.begin();it!=m.end();it++)
  {k=(it->first); hi=false;
    for(j=0;j<(it->second).size();j++)
    {int l=m[k][j];
      if(k!=l&&(s.find(l)!=s.end()))
        {hi=true; break; }
    }
   if(!hi) s1++;
  }
 cout<<s1;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,j,x,y,k,s1=0;bool hi;
  cin>>n; set<int> s;map<int,vector<int> > m;
  for(i=1;i<=n;i++)
   {
     cin>>x>>y;
    s.insert(x);
   m[y].push_back(x);
  }
 for(auto it=m.begin();it!=m.end();it++)
  {k=(it->first); hi=false;
    for(j=0;j<(it->second).size();j++)
    {int l=m[k][j];
      if(k!=l&&(s.find(l)!=s.end()))
       ;
      else s1++;
    }
  }
 cout<<s1;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,j,x,y,k,s1=0;bool hi;
  cin>>n; set<int> s;map<int,vector<int> > m;
  for(i=1;i<=n;i++)
   {
     cin>>x>>y;
    s.insert(x);
   m[y].push_back(x);
  }
 for(auto it=m.begin();it!=m.end();it++)
  {k=(it->first); hi=false;
    for(j=0;j<(it->second).size();j++)
    {int l=m[k][j];
      if(k!=l&&(s.find(l)!=s.end()))
        {hi=true; break; }
    }
   if(!hi) s1+=m[k].size();
  }
 cout<<s1;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,j,x,y,k,s1=0;bool hi;
  cin>>n; set<int> s;map<int,vector<int> > m;
  for(i=1;i<=n;i++)
   {
     cin>>x>>y;
    s.insert(y);
   m[y].push_back(x);
  }
 for(auto it=m.begin();it!=m.end();it++)
  {k=(it->first); hi=false;
    for(j=0;j<(it->second).size();j++)
    {int l=m[k][j];
      if(k!=l&&(s.find(l)!=s.end()))
       ;
      else s1++;
    }
  }
 cout<<s1;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,j,x,y,k,s1=0;bool hi;
  cin>>n; set<int> s;map<int,vector<int> > m;
  for(i=1;i<=n;i++)
   {
     cin>>x>>y;
    s.insert(y);
   m[y].push_back(x);
  }
 for(auto it=m.begin();it!=m.end();it++)
  {k=(it->first); hi=false;
    for(j=0;j<(it->second).size();j++)
    {int l=m[k][j];
      if(k!=l&&(s.find(l)!=s.end()))
       {hi=true;break;}
    }
   if(!hi) s1+=m[k].size();
  }
 cout<<s1;
}


/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first

int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  boost;

  ll n;
  cin >> n;
  ll t = n;
  ll ans = 0;
  ll arr[n + 1] = {0};
  while (n--)
  {
    ll x, y;
    cin >> x >> y;
    if (x != y)
      arr[y] = 1;

  }

  for (int i = 1; i <= t; i++)
  {
    if (arr[i] == 0)
      ans++;
  }
  cout << ans << endl;
}


/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first

int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  boost;

  ll n;
  cin >> n;
  ll t = n;
  ll ans = 0;
  ll arr[1001];
  while (n--)
  {
    ll x, y;
    cin >> x >> y;
    if (x != y)
      arr[y] = 1;
  }
  for (int i = 1; i <= t; i++)
  {
    if (arr[i] == 0)
      ans++;
  }

  cout << ans << endl;
}


/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first

int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  boost;

  ll n;
  cin >> n;
  unordered_set<ll>s;
  vector<pair<ll, ll>>arr;
  map<ll, ll>mp;
  for (int i = 1; i <= n; i++)
  {
    ll x, y;
    cin >> x >> y;
    arr.pb({x, y});
    mp[x]++;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++)
  {
    if (mp[arr[i].se])
    {
      if (arr[i].fi == arr[i].se)
      {
        if (mp[arr[i].fi] > 1)
          ans++;
      }
      else
      {
        ans++;
      }
    }

  }
  cout << n - ans << endl;

}


/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first

int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  boost;

  ll n;
  cin >> n;
  ll t = n;
  ll ans = 0;
  map<ll, ll>mp;
  while (n--)
  {
    ll x, y;
    cin >> x >> y;
    if (x != y)
      mp[y]++;

  }

  cout << t - mp.size() << endl;
}


/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first

ll pref[5001];
ll dp[5001][5001];
int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  boost;

  ll n;
  cin >> n;
  ll ans = 0;
  ll arr[n + 1] = {0};
  while (n--)
  {
    ll x, y;
    cin >> x >> y;
    if (x == y)
      continue;
    else
      arr[y] = 1;

  }
  for (int i = 1; i <= n; i++)
  {
    if (arr[i] == 0)
      ans++;
  }
  cout << ans << endl;
}


/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first

int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  boost;

  ll n;
  cin >> n;
  unordered_set<ll>s;
  vector<ll>arr;
  for (int i = 1; i <= n; i++)
  {
    ll x, y;
    cin >> x >> y;
    if (x != y)
    {
      s.insert(y);
    }
    arr.pb(x);

  }
  ll ans = 0;
  for (int i = 0; i < n; i++)
  {
    if (s.find(arr[i]) != s.end())
      ans++;

  }
  cout << ans << endl;
}


/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first

int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  boost;

  ll n;
  cin >> n;
  unordered_set<ll>s;
  vector<pair<ll, ll>>arr;
  map<ll, ll>mp;
  for (int i = 1; i <= n; i++)
  {
    ll x, y;
    cin >> x >> y;
    arr.pb({x, y});
    mp[x]++;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++)
  {
    if (mp[arr[i].se])
    {
      if (arr[i].fi == arr[i].se)
      {
        if (mp[arr[i].fi] > 1)
        {
          s.insert(arr[i].se);
        }

      }
      else
      {

        s.insert(arr[i].se);
      }
    }

  }
  for (int i = 0; i < n; i++)
  {
    if (s.find(arr[i].fi) == s.end())
      ans++;
  }
  cout << ans << endl;

}


/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first

int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  boost;

  ll n;
  cin >> n;
  unordered_set<ll>s;
  vector<pair<ll, ll>>arr;
  map<ll, ll>mp;
  map<ll, ll>mp2;
  for (int i = 1; i <= n; i++)
  {
    ll x, y;
    cin >> x >> y;
    arr.pb({x, y});
    if (x == y)
    {
      mp2[x]++;
    }
    mp[x]++;
  }
  for (int i = 0; i < n; i++)
  {
    if (mp[arr[i].se])
    {
      if (arr[i].se == arr[i].fi)
      {
        if (mp2[arr[i].fi] > 1)
        {
          mp[arr[i].fi] = 0;
        }
        else
        {
          mp[arr[i].fi] = 1;
        }
      }
      else
      {
        mp[arr[i].se] = 0;
      }
    }
  }
  ll ans = 0;
  for (auto x : mp)
  {
    ans += x.se;
  }
  cout << ans << endl;

}


/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first

int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  boost;

  ll n;
  cin >> n;
  unordered_set<ll>s;
  vector<ll>arr;
  for (int i = 1; i <= n; i++)
  {
    ll x, y;
    cin >> x >> y;
    if (x != y)
    {
      s.insert(y);
    }
    arr.pb(x);

  }
  ll ans = 0;
  for (int i = 0; i < n; i++)
  {
    if (s.find(arr[i]) == s.end())
      ans++;

  }
  cout << ans << endl;
}


/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first

int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  boost;

  ll n;
  cin >> n;
  unordered_set<ll>s;
  vector<pair<ll, ll>>arr;
  map<ll, ll>mp;
  for (int i = 1; i <= n; i++)
  {
    ll x, y;
    cin >> x >> y;
    arr.pb({x, y});
    mp[x]++;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++)
  {
    if (mp[arr[i].se])
    {
      if (arr[i].fi == arr[i].se)
      {
        if (mp[arr[i].se] > 1)
        {
          mp[arr[i].se] = 1;
        }
        else
        {
          mp[arr[i].se] = 0;
        }

      }
      else
      {

        mp[arr[i].se] = 0;
      }
    }

  }
  for (auto x : mp)
  {
    ans += x.se;
  }
  cout << ans << endl;

}


/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first

ll pref[5001];
ll dp[5001][5001];
int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  boost;

  ll n;
  cin >> n;
  ll ans = 0;
  ll arr[n + 1] = {0};
  while (n--)
  {
    ll x, y;
    cin >> x >> y;
    if (x == y)
      continue;
    arr[y] = 1;

  }
  for (int i = 1; i <= n; i++)
  {
    if (arr[i] == 0)
      ans++;
  }
  cout << ans << endl;
}


/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first

int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  boost;

  ll n;
  cin >> n;
  ll t = n;
  ll ans = 0;
  map<ll, ll>mp;
  unordered_set<ll>s;
  while (n--)
  {
    ll x, y;
    cin >> x >> y;
    if (x != y)
      mp[y]++;

    s.insert(x);
    s.insert(y);
  }

  cout << s.size() - mp.size() << endl;
}


/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first

ll pref[5001];
ll dp[5001][5001];
int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  boost;

  ll n;
  cin >> n;
  ll ans = 0;
  while (n--)
  {
    ll x, y;
    cin >> x >> y;
    if (x == y)
      ans++;
  }
  cout << ans << endl;
}


/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first

int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  boost;

  ll n;
  cin >> n;
  unordered_set<ll>s;
  vector<pair<ll, ll>>arr;
  map<ll, ll>mp;
  for (int i = 1; i <= n; i++)
  {
    ll x, y;
    cin >> x >> y;
    arr.pb({x, y});
    mp[x]++;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++)
  {
    bool ok = 0;
    for (int j = 0; j < n; j++)
    {
      if (i != j)
      {
        if (arr[j].se == arr[i].fi)
        {
          ok = 1;
          break;
        }

      }

    }
    if (ok)ans++;
  }
  cout << n - ans << endl;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int n;
	cin >> n;

	vector<int> a;
	vector<int> b;

	for(int i=0;i<n;i++) {
	    int x,y;
	    cin >> x >> y;
	    a.push_back(x);
	    b.push_back(y);
	}

	for(int i=0;i<n;i++) {
	    if(b[i] != a[i] && b[i] <= n && a[b[i]-1] > 0){
	        a[b[i]-1] *= -1;
	    }
	}

	int count = 0;
	for(int i=0;i<n;i++) {
	    if(a[i] > 0)
	        count++;
	}

	cout << count << endl;
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int n;
	cin >> n;

	vector<int> a;
	vector<int> b;
	vector<int> c;

	for(int i=0;i<n;i++) {
	    int x,y;
	    cin >> x >> y;

	    a.push_back(x);
	    b.push_back(y);
	    c.push_back(0);
	}

	for(int i=0;i<n;i++) {
	    if(a[i] != b[i] && b[i] <= n)
	        c[b[i]]++;
	}

	int count = 0;
	for(int i=0;i<n;i++) {
	   // c[b[i]] -= 1;
	    if(c[a[i]] == 0)
	        count++;

	   // c[b[i]] += 1;
	}

	cout << count << endl;
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int n;
	cin >> n;

	vector<int> a;
	vector<int> b;
	vector<int> c;

	for(int i=0;i<n;i++) {
	    int x,y;
	    cin >> x >> y;

	    a.push_back(x);
	    b.push_back(y);
	    c.push_back(0);
	}

	for(int i=0;i<n;i++) {
	   // if(a[i] != b[i])
	        c[b[i]]++;
	}

	int count = 0;
	for(int i=0;i<n;i++) {
	    c[b[i]] -= 1;
	    if(c[a[i]] == 0)
	        count++;

	    c[b[i]] += 1;
	}

	cout << count << endl;
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int n;
	cin >> n;

	vector<int> a;
	vector<int> b;

	for(int i=0;i<n;i++) {
	    int x,y;
	    cin >> x >> y;
	    a.push_back(x);
	    b.push_back(y);
	}

	for(int i=0;i<n;i++) {
	    if(b[i] != a[i] && a[i] > 0){
	        a[i] *= -1;
	    }
	}

	int count = 0;
	for(int i=0;i<n;i++) {
	    if(a[i] > 0)
	        count++;
	}

	cout << count << endl;
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int n;
	cin >> n;

	vector<int> a;
	vector<int> b;
	vector<int> c;

	for(int i=0;i<n;i++) {
	    int x,y;
	    cin >> x >> y;

	    a.push_back(x);
	    b.push_back(y);
	    c.push_back(0);
	}

	for(int i=0;i<n;i++) {
	    if(a[i] != b[i])
	        c[b[i]] = 1;
	}

	int count = 0;
	for(int i=0;i<n;i++) {
	    if(c[a[i]] == 0)
	        count++;
	}

	cout << count << endl;
	return 0;
}