Cheating

Правка en1, от Blackness, 2016-12-09 03:58:53

I'm afraid oyu8201 is cheating, his code:#include <bits/stdc++.h>

define fr(a, init, end) for(int a = init; a < end; ++a)

define add_wedge(a, b, c) to[z] = b; ant[z] = adj[a]; adj[a] = z; cost[z] = c; z++

define add_edge(a, b) to[z] = b; ant[z] = adj[a]; adj[a] = z++

define fre(i, u) for(int i = adj[u]; i != -1; i = ant[i])

define sc(a) scanf("%d", &a)

define debug(x) cerr << ">>> " << #x << " = " << x << endl;

define dbg(x) if(1) cerr << ">>> " << x << endl;

define _ << " , " <<

define endl '\n'

using namespace std;

typedef long long ll; typedef pair<int, int> ii;

const int N = int(1e6);

int col[N]; int to[N], ant[N], adj[N], z;

void dfs(int u) { fre(i, u) { if(col[to[i]] == -1) { col[to[i]] = col[u] ^ 1; dfs(to[i]); } } } int main() { ios::sync_with_stdio(false);cin.tie(NULL);

memset(col, -1, sizeof col);
memset(adj, -1, sizeof adj);
z = 0;

int n;
cin >> n;

int a, b;
vector<ii> p;

fr(i, 0, n)
{
    cin >> a >> b;
    --a, --b;
    add_edge(a, b);
    add_edge(b, a);
    p.push_back({a, b});
}

fr(i, 0, 2 * n)
{
    add_edge(i, i + 1);
    add_edge(i + 1, i);
    ++i;
}

fr(i, 0, 2 * n)
{
    if(col[i] == -1)
    {
        col[i] = 0;
        dfs(i);
    }
}

fr(i, 0, n)
{
    cout << col[p[i].first] + 1 << ' ' << col[p[i].second] + 1 << endl;
}

return 0;

}

my code: #include <bits/stdc++.h>

define fr(a, init, end) for(int a = init; a < end; ++a)

define add_wedge(a, b, c) to[z] = b; ant[z] = adj[a]; adj[a] = z; cost[z] = c; z++

define add_edge(a, b) to[z] = b; ant[z] = adj[a]; adj[a] = z++

define fre(i, u) for(int i = adj[u]; i != -1; i = ant[i])

define sc(a) scanf("%d", &a)

define debug(x) cerr << ">>> " << #x << " = " << x << endl;

define dbg(x) if(1) cerr << ">>> " << x << endl;

define _ << " , " <<

define endl '\n'

using namespace std;

typedef long long ll; typedef pair<int, int> ii;

const int N = int(1e6);

int col[N]; int to[N], ant[N], adj[N], z;

void dfs(int u) { fre(i, u) { if(col[to[i]] == -1) { col[to[i]] = col[u] ^ 1; dfs(to[i]); } } } int main() { ios::sync_with_stdio(false);cin.tie(NULL);

memset(col, -1, sizeof col);
memset(adj, -1, sizeof adj);
z = 0;

int n;
cin >> n;

int a, b;
vector<ii> p;

fr(i, 0, n)
{
    cin >> a >> b;
    --a, --b;
    add_edge(a, b);
    add_edge(b, a);
    p.push_back({a, b});
}

fr(i, 0, 2 * n)
{
    add_edge(i, i + 1);
    add_edge(i + 1, i);
    ++i;
}

fr(i, 0, 2 * n)
{
    if(col[i] == -1)
    {
        col[i] = 0;
        dfs(i);
    }
}

fr(i, 0, n)
{
    cout << col[p[i].first] + 1 << ' ' << col[p[i].second] + 1 << endl;
}

return 0;

}

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский Blackness 2016-12-09 03:58:53 3136 Initial revision (published)