제출 #281717

#제출 시각아이디문제언어결과실행 시간메모리
281717SamAnd친구 (IOI14_friend)C++17
11 / 100
1094 ms65540 KiB
#include "friend.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;

int n;
vector<int> g[N];

int q1, q2;
bool c[N];
void dfs(int x, int gg)
{
    c[x] = true;
    if (gg == 1)
        ++q1;
    else
        ++q2;
    for (int i = 0; i < g[x].size(); ++i)
    {
        int h = g[x][i];
        if (!c[h])
            dfs(h, 3 - gg);
    }
}

int findSample(int n, int confidence[], int host[], int protocol[])
{
    ::n = n;
    for (int i = 1; i < n; ++i)
    {
        if (protocol[i] == 0)
        {
            g[host[i]].push_back(i);
            g[i].push_back(host[i]);
        }
        else if (protocol[i] == 1)
        {
            for (int j = 0; j < g[host[i]].size(); ++j)
            {
                int h = g[host[i]][j];
                g[h].push_back(i);
                g[i].push_back(h);
            }
        }
        else
        {
            for (int j = 0; j < g[host[i]].size(); ++j)
            {
                int h = g[host[i]][j];
                g[h].push_back(i);
                g[i].push_back(h);
            }
            g[host[i]].push_back(i);
            g[i].push_back(host[i]);
        }
    }

    for (int i = 0; i < n; ++i)
        sort(g[i].begin(), g[i].end());

    int ans = 0;
    for (int x = 0; x < (1 << n); ++x)
    {
        int yans = 0;
        bool z = true;
        for (int i = 0; i < n; ++i)
        {
            if (!(x & (1 << i)))
                continue;
            yans += confidence[i];
            for (int j = 0; j < n; ++j)
            {
                if (!(x & (1 << j)))
                    continue;
                if (binary_search(g[i].begin(), g[i].end(), j))
                {
                    z = false;
                    break;
                }
            }
            if (!z)
                break;
        }
        if (z)
            ans = max(ans, yans);
    }
    return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

friend.cpp: In function 'void dfs(int, int)':
friend.cpp:18:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int i = 0; i < g[x].size(); ++i)
      |                     ~~^~~~~~~~~~~~~
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:38:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |             for (int j = 0; j < g[host[i]].size(); ++j)
      |                             ~~^~~~~~~~~~~~~~~~~~~
friend.cpp:47:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |             for (int j = 0; j < g[host[i]].size(); ++j)
      |                             ~~^~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...