Submission #348380

# Submission time Handle Problem Language Result Execution time Memory
348380 2021-01-14T20:35:03 Z iliccmarko Game (IOI14_game) C++14
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 1000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define single_case solve();
#define line cerr<<"----------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL); }
#define mod 1000000007LL
int n;
const int N = 1505;
int parent[N], s[N];
int cnt[N][N];

int find_parent(int u)
{
    while(u!=parent[u])
    {
        parent[u] = parent[parent[u]];
        u = parent[u];
    }
    return u;
}

void _union(int u, int v)
{
    u = find_parent(u);
    v = find_parent(v);
    if(u!=v)
    {
        if(s[u]<s[v]) swap(u, v);
        for(int i = 1;i<=n;i++)
        {
            cnt[i][u] += cnt[i][v];
        }
        parent[v] = u;
        s[u] += s[v];
    }
}

void initialize(int N)
{
    n = N;
    for(int i = 1;i<=n;i++) parent[i] = i, s[i] = 1;
}

int hasEdge(int u, int v)
{
    int a = find_parent(u);
    int b = find_parent(v);
    for(int i = 1;i<=n;i++) parent[i] = find_parent(i);
    int w = s[a]*s[b]/2;
    for(int i = 1;i<=n;i++)
    {
        w -= cnt[i][a];
    }
    if(w==1)
    {
        cnt[u][b]++;
        cnt[v][a]++;
        _union(a, b);
        return 1;
    }
    return 0;
}

# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -