Cod sursa(job #2882850)

Utilizator CaptnBananaPetcu Tudor CaptnBanana Data 31 martie 2022 20:51:49
Problema Felinare Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("felinare.in");
ofstream g("felinare.out");

const int N = 8192;
int n, m, x, y, pereche[N], pereche2[N], felinare, stanga, dreapta; // lui pereche2 i se asociaza felinarele secundare
vector<int> c[N], c2[N];
bool viz[N];

int main(){
    f >> n >> m;
    for(int i = 0; i < m; i++){
        f >> x >> y;
        c[x].push_back(y);
        c2[y].push_back(x);
    }

    f.close();
    for(int i = 1; i <= n; i++){
        if(c[i].size() == 0)
            felinare++;
        else
            stanga++;

        if(c2[i].size() == 0)
            felinare++;
        else
            dreapta++;
    }

    g << felinare + max(stanga, dreapta) << '\n';
    for(int i = 1; i <= n; i++){
        int rep = 0;
        if(c[i].size() == 0 || stanga > dreapta)
            rep |= 1;

        if(c2[i].size() == 0 || dreapta >= 0)
            rep |= 2;

        g << rep << '\n';
    }

    g.close();
}