Submission #655148

#TimeUsernameProblemLanguageResultExecution timeMemory
655148jophyyjhGame (IOI14_game)C++14
100 / 100
270 ms16440 KiB
/**
 * A pretty straight-forward problem. The problem asks us to "confuse" the player by
 * only letting him/her know the graph's connectivity at the very last moment.
 * 
 * In order to be "between" connected and disconnected, it makes sense to have a
 * small (~O(n)) number of edges. Moreover, whether each edge is present shall be
 * determined by what edges are actually asked by the player. Here's my solution:
 *    First imagine that all edges have the state "undecided". At the beginning,
 *    all edges are "by default" present (we'll find out the actual ans when
 *    the player asks for it). When the player asks for a new edge {u,v}, we
 *    see whether not including {u,v} makes the graph disconnected, assuming
 *    that all "undecided" edges are included.
 *    If it does, we must include {u,v}; otherwise, we exclude it from the
 *    graph since there're other undecided edges that preserve connectivity.
 *    Finally, we flag the edge as "decided".
 * One can prove by induction that nC2 queries are required before we can determine
 * connectivity. This may look elegant, but the problem is that finding connectivity
 * with edge removal is difficult (O(n^4), only passing the first 2 subtasks...).
 * 
 * After thinking for a while, I modified my solution above. First, let's consider
 * all the potential edges incident to (n-1): {n-2,n-1}, {n-3,n-1}, ..., {0,n-1}. It
 * only takes one of them to make node (n-1) connected to the other nodes, so we can
 * simply include the last potential edge asked by the player (which is incident to
 * n-1). In this way, n-1 is certainly linked to another node with a smaller index.
 * Moreover, the remaining n-1 nodes' connectivity isn't affected by node n-1, so
 * the same goes for the remaining n-1 nodes. Nice~
 * 
 * Time Complexity: O(n^2)
 * Implementation 1
*/

#include <bits/stdc++.h>
#include "game.h"

typedef std::vector<int>    vec;


vec left;

void initialize(int n) {
    left.resize(n);
    for (int k = 0; k < n; k++)
        left[k] = k;
}

int hasEdge(int u, int v) {
    if (u > v)
        std::swap(u, v);
    left[v]--;
    return left[v] == 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...