Cod sursa(job #2712652)

Utilizator PatrickCplusplusPatrick Kristian Ondreovici PatrickCplusplus Data 26 februarie 2021 11:13:35
Problema Ubuntzei Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.42 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("domino.in");
ofstream fout("domino.out");

const int nmax = 100005, mmax = 500005;
int n, m, from[mmax], to[mmax], start;
bool viz[mmax], viz2[nmax];

vector <int> G[10];
vector <pair <int, int> > G2[10];

int main(){
    fin >> m;
    for (int i = 1; i <= m; ++i){
        int x, y;
        fin >> x >> y;
        G[x].push_back(i);
        G[y].push_back(i);
        G2[x].push_back({i, 0});
        G2[y].push_back({i, 1});
        from[i] = x;
        to[i] = y;
        start = x;

    }
    bool euler = true;
    vector <int> s, ans;
    s.push_back(start);
    while (s.size() > 0){
        int nod = s.back();
        if (G[nod].size() > 0){
            int muchie = G[nod].back();
            G[nod].pop_back();
            if (viz[muchie] == false){
                viz[muchie] = true;
                s.push_back(from[muchie] + to[muchie] - nod);
            }
        }
        else{
            ans.push_back(nod);
            s.pop_back();
        }
    }
    ans.pop_back();
    fout << 1 << "\n";
    for (auto it : ans){
        while (G2[it].size() > 0){
            if (viz2[G2[it].back().first] == false){
                fout << G2[it].back().first << " " << G2[it].back().second << "\n";
                viz2[G2[it].back().first] = true;
            }
            G2[it].pop_back();
        }
    }
    return 0;
}