Submission #202039

# Submission time Handle Problem Language Result Execution time Memory
202039 2020-02-13T08:00:11 Z HellAngel Split the Attractions (IOI19_split) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 100007;
int ans, sz[maxn], n, m;
int col[maxn];
pair<int, int> a[4];
vector<int> vt[maxn];

void DFS(int u, int p)
{
    sz[u] = 1;
    for(auto v: vt[u])
    {
        if(v != p)
        {
            DFS(v, u);
            sz[u] += sz[v];
        }
    }
}

int FindCen(int u, int p)
{
    int Big = -1;
    bool ok = true;
    for(auto v: vt[u])
    {
        if(v == p) continue;
        if(sz[v] * 2 > sz[1]) ok = false;
        if(Big == -1 || sz[Big] < sz[v]) Big = v;
    }
    if(ok) return u;
    return FindCen(Big, u);
}

void Solve(int cur, int par, int type1, int type2)
{
    vector<int> ahihi;
    queue<pair<int, int>> q;
    q.emplace(cur, par);
    while(!q.empty())
    {
        pair<int, int> p = q.front();
        q.pop();
        ahihi.push_back(p.first);
        for(auto i: vt[p.first])
        {
            if(i == p.second) continue;
            q.emplace(i, p.first);
        }
    }
    for(int i = 0; i < ahihi.size(); i++)
    {
        if(i < a[type1].first) col[ahihi[i]] = a[type1].second;
        else col[ahihi[i]] = a[type2].second;
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
    cin >> n >> m >> a[1].first >> a[2].first >> a[3].first;
    a[1].second = 1;
    a[2].second = 2;
    a[3].second = 3;
    sort(a + 1, a + 4);
    for(int i = 1; i <= m; i++)
    {
        int u, v;
        cin >> u >> v;
        vt[u].push_back(v);
        vt[v].push_back(u);
    }
    DFS(1, 1);
    int root = FindCen(1, 1);
    DFS(root, root);
    int nxt = -1;
    for(auto i: vt[root])
    {
        if(sz[i] >= a[1].first)
        {
            if(nxt == -1 || sz[nxt] > sz[i]) nxt = i;
        }
    }
    if(nxt == -1)
    {
        for(int i = 1; i <= n; i++) cout << 0 << ' ';
        exit(0);
    }
    Solve(nxt, root, 1, 3);
    Solve(root, nxt, 2, 3);
    for(int i = 1; i <= n; i++)
    {
        cout << col[i] << ' ';
    }

}

Compilation message

split.cpp: In function 'void Solve(long long int, long long int, long long int, long long int)':
split.cpp:53:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < ahihi.size(); i++)
                    ~~^~~~~~~~~~~~~~
split.cpp: In function 'int32_t main()':
split.cpp:64:39: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
                                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
/tmp/ccw1NYzH.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cc53E5bG.o:split.cpp:(.text.startup+0x0): first defined here
/tmp/ccw1NYzH.o: In function `main':
grader.cpp:(.text.startup+0x27a): undefined reference to `find_split(int, int, int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status