Submission #1063729

#TimeUsernameProblemLanguageResultExecution timeMemory
1063729aaaaaarrozSplit the Attractions (IOI19_split)C++17
11 / 100
52 ms13260 KiB
#include "split.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
    vector<vector<int>> graph(n);
    for (int i = 0; i < p.size(); i++) {
        graph[p[i]].push_back(q[i]);
        graph[q[i]].push_back(p[i]);
    }

    vector<int> ans(n, 0);
    vector<int> nodes_b;
    queue<int> cola;
    cola.push(0);
    vector<bool> visited(n, false);
    visited[0] = true;

    while (!cola.empty() && nodes_b.size() < b) {
        int nodo = cola.front();
        cola.pop();
        nodes_b.push_back(nodo);
        for (int vecino : graph[nodo]) {
            if (!visited[vecino]) {
                visited[vecino] = true;
                cola.push(vecino);
            }
        }
    }

    if (nodes_b.size() != b) {
        return vector<int>(n, 0);
    }
    for (int nodo : nodes_b) {
        ans[nodo] = 2;
    }
    vector<int> nodes_c;
    for (int i = 0; i < n; i++) {
        if (ans[i] == 0 && nodes_c.size() < c) {
            ans[i] = 3;
            nodes_c.push_back(i);
        }
    }
    if (nodes_c.size() != c) {
        return vector<int>(n, 0); 
    }
    for (int i = 0; i < n; i++) {
        if (ans[i] == 0) {
            ans[i] = 1; 
        }
    }
    return ans;
}

Compilation message (stderr)

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:7:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |     for (int i = 0; i < p.size(); i++) {
      |                     ~~^~~~~~~~~~
split.cpp:19:44: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   19 |     while (!cola.empty() && nodes_b.size() < b) {
      |                             ~~~~~~~~~~~~~~~^~~
split.cpp:31:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |     if (nodes_b.size() != b) {
      |         ~~~~~~~~~~~~~~~^~~~
split.cpp:39:43: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |         if (ans[i] == 0 && nodes_c.size() < c) {
      |                            ~~~~~~~~~~~~~~~^~~
split.cpp:44:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |     if (nodes_c.size() != c) {
      |         ~~~~~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...