Submission #564091

#TimeUsernameProblemLanguageResultExecution timeMemory
564091myrcella게임 (IOI14_game)C++17
Compilation error
0 ms0 KiB
//by szh
#include "game.h"
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}

const int maxn = 1555;

int f[maxn];
int sz[maxn];
int cnt[maxn][maxn];
int cntt[maxn];

set <int> s;

void initialize(int n) {
	rep(i,0,n) f[i]=i,sz[i]=1,s.insert(i);
	memset(cnt,0,sizeof(cnt));
	memset(cntt,0,sizeof(cntt));
	return;
}

int getf(int u) {
	if (f[u]==u) return u;
	else return f[u] = getf(f[u]);
}

int what = 0;

bool check(int rt) {
//	debug(sz[rt]*(n-sz[rt])); debug(cntt[rt]);
	if (sz[rt]*(n-sz[rt])-1==cntt[rt]) return true;
	else return false;
}

int hasEdge(int u,int v) {
	int fu = getf(u),fv = getf(v);
	if (fu==fv) return 0;
	if (check(fu) or check(fv)) {
		f[fu] = fv;
		sz[fv] += sz[fu];
		s.erase(fu);
		cntt[fv]=0;
		for (auto it:s) {
			if (it==fv) continue;
			cnt[fv][it] += cnt[fu][it];
			cnt[it][fv] += cnt[fu][it];
			assert(cnt[it][fv]==cnt[fv][it]);
			cntt[fv] += cnt[fv][it];
		}
		what++;
		assert(what<n);
		return 1;
	}
	else {
		cnt[u][v]++;
		cnt[v][u]++;
		cntt[u]++;
		cntt[v]++;
		return 0;
	}
}
/*
int read_int() {
    int x;
    assert(scanf("%d", &x) == 1);
    return x;
}

int main() {
    int n, u, v;
    n = read_int();
    initialize(n);
    for (int i = 0; i < n * (n - 1) / 2; i++) {
        u = read_int();
        v = read_int();
        printf("%d\n", hasEdge(u, v));
    }
    return 0;
}
*/

Compilation message (stderr)

game.cpp: In function 'bool check(int)':
game.cpp:50:14: error: 'n' was not declared in this scope
   50 |  if (sz[rt]*(n-sz[rt])-1==cntt[rt]) return true;
      |              ^
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from game.cpp:3:
game.cpp: In function 'int hasEdge(int, int)':
game.cpp:70:15: error: 'n' was not declared in this scope
   70 |   assert(what<n);
      |               ^
game.cpp: In function 'bool check(int)':
game.cpp:52:1: warning: control reaches end of non-void function [-Wreturn-type]
   52 | }
      | ^