답안 #111888

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
111888 2019-05-16T16:23:57 Z model_code Meetings (JOI19_meetings) C++17
29 / 100
2000 ms 512 KB
#include "meetings.h"
 
#include <cstdio>
#include <vector>
#include <algorithm>
 
using namespace std;
 
const int MAXN = 2000;
 
int N;
vector<int> graph[MAXN];
bool appended[MAXN];
bool active[MAXN];
int subsize[MAXN];
 
void add_edge(int u, int v)
{
    graph[u].push_back(v);
    graph[v].push_back(u);
}
void remove_edge(int u, int v)
{
    graph[u].erase(find(graph[u].begin(), graph[u].end(), v));
    graph[v].erase(find(graph[v].begin(), graph[v].end(), u));
}
 
int visit1(int p, int rt = -1)
{
    if (!active[p]) return 0;
    int ret = 1;
    for (int q : graph[p]) if (q != rt) {
        ret += visit1(q, p);
    }
    return subsize[p] = ret;
}
int visit2(int p, int sz, int rt = -1)
{
    if (!active[p]) return -1;
    int upsize = sz - 1;
    bool isok = true;
    for (int q : graph[p]) if (q != rt && active[q]) {
        int res = visit2(q, sz, p);
        if (res != -1) return res;
        upsize -= subsize[q];
        if (subsize[q] > sz / 2) isok = false;
    }
    if (isok && upsize <= sz / 2) return p;
    return -1;
}
 
void append_internal(int seed, int target)
{
    int sz = visit1(seed);
 
    if (sz == 1) {
        add_edge(seed, target);
        return;
    }
    if (sz == 2) {
        int s = seed, t;
        for (int v : graph[s]) {
            if (active[v]) t = v;
        }
 
        int q = Query(s, t, target);
        if (q == s || q == t) {
            appended[target] = true;
            add_edge(q, target);
        } else {
            remove_edge(s, t);
            add_edge(s, q);
            add_edge(q, t);
            appended[target] = true;
            appended[q] = true;
            if (q != target) {
                add_edge(q, target);
            }
        }
        return;
    }
 
    int g = visit2(seed, sz);
    visit1(g);
 
    vector<pair<int, int>> nbs;
    for (int u : graph[g]) {
        if (active[u]) nbs.push_back({subsize[u], u});
    }
    sort(nbs.rbegin(), nbs.rend());
 
    for (int i = 0; i < nbs.size(); i += 2) {
        if (i == nbs.size() - 1) {
            append_internal(nbs[i].second, target);
            return;
        }
 
        int u = nbs[i].second, v = nbs[i + 1].second;
        int q = Query(u, v, target);
 
        if (q == u || q == v) {
            active[g] = false;
            append_internal(q, target);
            return;
        } else if (q == g) {
            active[u] = active[v] = false;
            continue;
        } else {
            int side = (Query(u, g, target) == g) ? v : u;
            appended[target] = true;
            appended[q] = true;
            remove_edge(g, side);
            add_edge(g, q);
            add_edge(q, side);
            if (q != target) {
                add_edge(q, target);
            }
            return;
        }
    }
    add_edge(g, target);
    return;
}
 
void append(int v)
{
    fill(active, active + N, true);
    append_internal(0, v);
}
 
void Solve(int N)
{
    ::N = N;
  while(N > 300);
 
    graph[0].push_back(1);
    graph[1].push_back(0);
 
    appended[0] = appended[1] = true;
    fill(appended + 2, appended + N, false);
 
    for (int v = 2; v < N; ++v) {
        if (!appended[v]) append(v);
    }
 
    for (int u = 0; u < N; ++u) {
        for (int v : graph[u]) if (u < v) {
            Bridge(u, v);
        }
    }
}

Compilation message

meetings.cpp: In function 'void append_internal(int, int)':
meetings.cpp:92:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < nbs.size(); i += 2) {
                     ~~^~~~~~~~~~~~
meetings.cpp:93:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (i == nbs.size() - 1) {
             ~~^~~~~~~~~~~~~~~~~
meetings.cpp: In function 'void Solve(int)':
meetings.cpp:134:3: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   while(N > 300);
   ^~~~~
meetings.cpp:136:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
     graph[0].push_back(1);
     ^~~~~
meetings.cpp: In function 'void append_internal(int, int)':
meetings.cpp:71:24: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
             remove_edge(s, t);
             ~~~~~~~~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 444 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 300 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 444 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 300 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 304 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 444 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 300 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 304 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 8 ms 512 KB Output is correct
29 Correct 8 ms 384 KB Output is correct
30 Correct 9 ms 384 KB Output is correct
31 Correct 8 ms 512 KB Output is correct
32 Correct 9 ms 384 KB Output is correct
33 Correct 11 ms 512 KB Output is correct
34 Correct 15 ms 432 KB Output is correct
35 Correct 13 ms 512 KB Output is correct
36 Correct 12 ms 512 KB Output is correct
37 Correct 13 ms 512 KB Output is correct
38 Correct 14 ms 512 KB Output is correct
39 Correct 12 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3053 ms 512 KB Time limit exceeded
2 Halted 0 ms 0 KB -