Submission #645130

#TimeUsernameProblemLanguageResultExecution timeMemory
645130s7monSplit the Attractions (IOI19_split)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 2e5 + 5;

int n, m, a, b, c;
vector<int> adj[N];

namespace sub1{
    int va = 0, vb = 1, cnta = 0, cntb = 0;
    int sz[N], lab[N], par[N];

    void dfs(int u, int pu){
        if ( va ) return;

        sz[u] = 1;
        for (int v : adj[u]) if ( v != pu ){
            dfs(v, u);
            par[v] = u;
            sz[u] += sz[v];
        }

        bool ck = ( sz[u] >= a );
        for (int v : adj[u]) if ( v != pu )
            ck &= ( sz[v] < a );

        if ( ck ) va = u;
    }

    void dfsa(int u){
        if ( cnta == a ) return;
        cnta ++; lab[u] = 1;
//        cout << u << ' ' << lab[u] << '\n';
        for (int v : adj[u]) if ( v != par[u] && v != vb )
            dfsa(v);
    }

    void dfsb(int u){
        if ( cntb == b ) return;
        cntb ++; lab[u] = 2;
//        cout << u << ' ' << lab[u] << '\n';
        for (int v : adj[u]) if ( v != par[u] && v != va )
            dfsb(v);
    }

    void solve(){
        dfs(1, 0);
        if ( n - sz[va] < a ){
            for (int i = 1; i <= n; i ++)
                cout << 0 << ' ';
            return;
        }
        else{
            if ( sz[va] >= b ) swap(vb, va);
            for (int i = 1; i <= n; i ++) lab[i] = 3;

            dfsa(va);
            dfsb(vb);
            for (int i = 1; i <= n; i ++)
                cout << lab[i] << ' ';
        }
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    if ( fopen("split.inp", "r") ){
        freopen("split.inp", "r", stdin);
        freopen("split.out", "w", stdout);
    }

    cin >> n >> m >> a >> b >> c;
    for (int i = 1; i <= m; i ++){
        int u, v;
        cin >> u >> v;
        u ++, v ++;
        adj[u].pb(v);
        adj[v].pb(u);
    }

    if ( m == n - 1 ) sub1::solve();

    return 0;
}

Compilation message (stderr)

split.cpp: In function 'int main()':
split.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen("split.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
split.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen("split.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccjtlFT5.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccUZUAm5.o:split.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccjtlFT5.o: in function `main':
grader.cpp:(.text.startup+0x25e): 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