Source Code
#include <bits/stdc++.h>
using namespace std;
 
#define S second
#define F first
#define LL long long 
#define LINF 100000000000000000
#define INF 1000000000
 
const int N = 2e5+10;
const LL MOD = 1e9+7;

set<pair<int,int>>st;
vector<int>adj[N];
int a[N];

int main()
{      
    //freopen("out.txt","w",stdout);

    int n,k,m;
    scanf("%d%d%d",&n,&k,&m);

    int cnt = 0;
    for(int i=1;i<=m;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        swap(u,v);
        if(st.find({u,v})!=st.end())continue;
        st.insert({u,v});

        if(!a[v])cnt++;
        a[v]++;
        adj[u].push_back(v);
    }

    int ans = cnt;
    for(int i=1;i<=n;i++){
        for(auto x:adj[i]){
            a[x]--;
            if(!a[x])cnt--;
        }
        
        ans = min(ans,1+cnt);
        
        for(auto x:adj[i]){
            if(!a[x])cnt++;
            a[x]++;
        }
    }

    printf("%d\n",ans);
}
Copy
Min Vertex Cover 1 Hazem17
GNU G++17
155 ms
11.1 MB
Wrong Answer