Submission #835382

# Submission time Handle Problem Language Result Execution time Memory
835382 2023-08-23T13:57:22 Z Liudas Friend (IOI14_friend) C++17
11 / 100
21 ms 1388 KB
#include <cstdio>
#include <cassert>
#define __MAXSIZE__ 100002
#include "friend.h"
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#define __MAXSIZE__ 100002
using namespace std;
void getmax(int head, int N, vector<vector<int>> &arr, int &m, set<int> been, int score, int conf[]){
    if(head == N){
        m = max(m, score);
        return;
    }
    set<int> nbeen = been;
    for(int i : arr[head]){
        nbeen.insert(i);
    }
    getmax(head + 1, N, arr, m, been, score, conf);
    if(been.find(head) == been.end())
    getmax(head + 1, N, arr, m, nbeen, score + conf[head], conf);
}
void dfs(int head, int par, vector<vector<int>> &arr, vector<int> &val, vector<int> &bel){
    int v = 0;
    for(int i : arr[head]){
        if(i != par){
            dfs(i, head, arr, val, bel);
            v += max(bel[i], val[i]);
            bel[head] += val[i];
        }
    }
    val[head] = v;
}
struct node{
    set<int> child;
};
int findSample(int n,int confidence[],int host[],int protocol[]){
    int N = n;
    if(n <= 10){
        vector<vector<int>> arr(N);
        for(int i = 1; i < N; i ++){
            int h = host[i];
            if(protocol[i] == 0){
                arr[i].push_back(h);
                arr[h].push_back(i);
            }
            if(protocol[i] == 1){
                for(int j : arr[h]){
                    arr[i].push_back(j);
                    arr[j].push_back(i);
                }
            }
            if(protocol[i] == 2){
                arr[i].push_back(h);
                arr[h].push_back(i);
                for(int j : arr[h]){
                    arr[i].push_back(j);
                    arr[j].push_back(i);
                }
            }
        }
        int m = 0;
        set<int> brr;
        getmax(0, N, arr, m, brr, 0, confidence);
        return m;
    }
    else{
        if(count(protocol, protocol + n, 0) + count(protocol, protocol + n, 1) == n - 1){
            vector<node> brr(N);
            for(int i = 1; i < N; i ++){
                int h = host[i];
                if(protocol[i] == 0){
                    brr[i].child.insert(h);
                    brr[h].child.insert(i);
                }
                else{
                    for(int j : brr[h].child){
                        brr[i].child.insert(j);
                    }
                }
            }
            int c = 0;
            for(int i = 0; i < N; i ++){
                int mv = 1e9;
                for(int j = 0; j < N; j ++){
                    if(brr[j].child.size()){
                        mv = min(mv, (int)brr[j].child.size());
                    }
                }
                for(int j = 0; j < N; j ++){
                    if(brr[i].child.size() != mv)continue;
                    for(int k : brr[j].child){
                        brr[k].child.clear();
                    }
                    brr[j].child.clear();
                    c++;
                    break;
                }
            }
            return c;
        }
    }
    return 0;
}

Compilation message

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:92:44: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   92 |                     if(brr[i].child.size() != mv)continue;
      |                        ~~~~~~~~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Incorrect 21 ms 1388 KB Output isn't correct
13 Halted 0 ms 0 KB -