답안 #348391

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
348391 2021-01-14T20:57:38 Z iliccmarko 게임 (IOI14_game) C++14
컴파일 오류
0 ms 0 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];
vector<int> g[N];

int find_parent(int u)
{
    if(parent[u]==u) return u;
    return parent[u] = find_parent(parent[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];
        }
        for(int x : g[v])
        {
            g[u].pb(x);
        }
        parent[v] = u;
        s[u] += s[v];
    }
}

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

int hasEdge(int u, int v)
{
    u++;
    v++;
    int a = find_parent(u);
    int b = find_parent(v);
    int w = s[a]*s[b];
    if(s[b]<s[a])
    {
        for(int i : g[b])
        {
            w -= cnt[i][a];
        }
    }
    else
        for(int i : g[a])
    {
        w -= cnt[i][b];
    }
    //cout<<u<<" "<<v<<" "<<a<<" "<<b<<" "<<w<<endl;
    cnt[u][b]++;
    cnt[v][a]++;
    if(w==1)
    {
        _union(a, b);
        return 1;
    }
    return 0;
}

Compilation message

game.cpp: In function 'void initialize(int)':
game.cpp:50:21: warning: for increment expression has no effect [-Wunused-value]
   50 |     for(int i = 1;;i<=n;i++) g[i].pb(i);
      |                    ~^~~
game.cpp:50:24: error: expected ')' before ';' token
   50 |     for(int i = 1;;i<=n;i++) g[i].pb(i);
      |        ~               ^
      |                        )
game.cpp:50:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   50 |     for(int i = 1;;i<=n;i++) g[i].pb(i);
      |     ^~~
game.cpp:50:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   50 |     for(int i = 1;;i<=n;i++) g[i].pb(i);
      |                         ^
game.cpp:50:25: error: 'i' was not declared in this scope