답안 #775338

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
775338 2023-07-06T09:49:55 Z danikoynov 친구 (IOI14_friend) C++14
0 / 100
1 ms 468 KB
#include "friend.h"
#include<bits/stdc++.h>

using namespace std;

// Find out best sample
const int maxn = 1010;
typedef long long ll;

vector < int > adj[maxn];
void add_edge(int v, int u)
{
    adj[v].push_back(u);
    adj[u].push_back(v);
}

vector < int > ord;
int used[maxn];
void bfs(int v)
{
    queue < int > q;
    used[v] = 1;
    q.push(v);
    while(!q.empty())
    {
        int cur = q.front();
        q.pop();
        ord.push_back(cur);
        for (int u : adj[cur])
        {

            if (used[u] == 0)
            {
                if (used[cur] == 1)
                    used[u] = 2;
                else
                    used[u] = 1;
                q.push(u);
            }
            assert(used[u] != used[cur]);
        }
    }
}
int findSample(int n,int confidence[],int host[],int protocol[])
{
    bool only_my = true, only_we = true;
    for (int i = 1; i < n; i ++)
    {
        if (protocol[i] != 1)
            only_my = false;
        if (protocol[i] != 2)
            only_we = false;
    }
    /**if (only_my)
    {

        int ans = 0;
        for (int i = 0; i < n; i ++)
            ans += confidence[i];
        return ans;
    }
    else
    if (only_we)
    {
        int ans = 0;
        for (int i = 0; i < n; i ++)
            ans = max(ans, confidence[i]);
        return ans;
    }
    else*/
    {
        for (int i = 1; i < n; i ++)
        {
            if (protocol[i] == 0)
            {
                add_edge(i, host[i]);
            }
            else
            {
                assert(0);
            }
            /**if (protocol[i] == 2)
            {
                for (int u : adj[host[i]])
                    add_edge(u, i);
            }*/
        }
        ll ans = 0;
        for (int i = 0; i < n; i ++)
        {
            if (!used[i])
            {
                ord.clear();
                bfs(i);
                int s1 = 0, s2 = 0;
                for (int v : ord)
                {
                    if (used[v] == 1)
                        s1 += confidence[v];
                    else
                        s2 += confidence[v];
                }
                ans = ans + max(s1, s2);
            }

        }

        return ans;
    }


}

Compilation message

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:46:10: warning: variable 'only_my' set but not used [-Wunused-but-set-variable]
   46 |     bool only_my = true, only_we = true;
      |          ^~~~~~~
friend.cpp:46:26: warning: variable 'only_we' set but not used [-Wunused-but-set-variable]
   46 |     bool only_my = true, only_we = true;
      |                          ^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Runtime error 1 ms 468 KB Execution killed with signal 6
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Runtime error 1 ms 468 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -