Submission #303206

# Submission time Handle Problem Language Result Execution time Memory
303206 2020-09-20T01:43:10 Z shrek12357 Calvinball championship (CEOI15_teams) C
0 / 100
2 ms 512 KB
#include <stdio.h>
#include <stdlib.h>

#define MAXN 100000

struct edge
{
  int to;
  struct edge *next;
};

static struct edge *ns[MAXN];
static int color[MAXN];

static int perm[MAXN];

static int
first_available (int v, int c)
{
  int av[c];
  int i;
  struct edge *e;

  for (i = 0; i < c; i++)
    av[i] = 1;

  for (e = ns[v]; e; e = e->next)
    if (color[e->to] != -1)
      av[color[e->to]] = 0;

  for (i = 0; i < c; i++)
    if (av[i])
      return i;
  return c;
}

static void
addhe (int f, int t)
{
  struct edge *e = malloc (sizeof (struct edge));

  e->to = t;
  e->next = ns[f];
  ns[f] = e;
}

static void
adde (int f, int t)
{
  addhe (f, t);
  addhe (t, f);
}

int main (int argc, char *argv[])
{
  int n, m, i, k, f, t, c = 0;

  scanf ("%d%d", &n, &m);

  for (i = 0; i < n; i++)
    {
      perm[i] = i;
      color[i] = -1;
    }

  if (argc > 1)
    {
      for (i = 0; i < n; i++)
	perm[i] = n - i - 1;
      if (argv[1][0] == 'x')
	{
	  srand (0);
	  for (i = 0; i < n; i++)
	    {
	      int w = i + rand () % (n - i);
	      int p = perm[i];
	      perm[i] = perm[w];
	      perm[w] = p;
	    }
	}
    }


  for (i = 0; i < m; i++)
    {
      scanf ("%d%d", &f, &t);
      f--;
      t--;
      adde (f, t);
    }

  for (i = 0; i < n; i++)
    {
      int pi = perm[i];
      color[pi] = first_available (pi, c);
      if (color[pi] >= c)
	c = color[pi] + 1;
    }

  printf ("%d\n", c);
  for (k = 0; k < c; k++)
    {
      for (i = 0; i < n; i++)
	if (color[i] == k)
	  printf ("%d ", i + 1);
      printf ("\n");
    }

  return 0;
}

Compilation message

teams.c: In function 'main':
teams.c:58:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   58 |   scanf ("%d%d", &n, &m);
      |   ^~~~~~~~~~~~~~~~~~~~~~
teams.c:86:7: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   86 |       scanf ("%d%d", &f, &t);
      |       ^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 512 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -