Submission #1177718


Source Code Expand

Copy
#pragma GCC target ("arch=sandybridge")

#include <unistd.h>
#include <string.h>
#include <stdlib.h>

char ibuf[3000018];
char *ibufe = ibuf-1;

void readall(){
  int k, t = 0;
  while((k=read(STDIN_FILENO, ibuf+t, sizeof(ibuf)-t))>0) t += k;
  if(t>=sizeof(ibuf)) exit(0);
}

int read_uint(){
  int x=0;
  while(*(++ibufe) <'0');
  do {
    x *= 10;
    x += *ibufe-'0';
  } while(*(++ibufe) >='0');

  return x;
}

char buf[800001];
char *bufe = buf;

void write_yesno(int b){
  if(b){
    *bufe++ = 'Y';
    *bufe++ = 'e';
    *bufe++ = 's';
  }
  else {
    *bufe++ = 'N';
    *bufe++ = 'o';
  }
  *bufe++ = '\n';
}

void flush(){
  write(STDOUT_FILENO, buf, bufe-buf);
}

int tree[100000];

int root(int i){
  if(tree[i]<0) return i;
  return tree[i] = root(tree[i]);
}

void unite(int i, int j){
  int ri = root(i);
  int rj = root(j);
  if(ri == rj) return;
  if(tree[ri] == tree[rj]){
    tree[rj] = ri;
    tree[ri]--;
  }
  else if(tree[ri] < tree[rj])
    tree[rj] = ri;
  else
    tree[ri] = rj;
}

int main(){
  int q, i;
  memset(tree, -1, sizeof(tree));
  readall();
  read_uint();
  q = read_uint();
  for(i=0;i<q;i++){
    int p = read_uint();
    int a = read_uint();
    int b = read_uint();
    if(p)
      write_yesno(root(a) == root(b));
    else
      unite(a, b);
  }

  flush();
  return 0;
}

Submission Info

Submission Time
Task B - Union Find
User ryuhei
Language C (GCC 5.4.1)
Score 100
Code Size 1404 Byte
Status
Exec Time 6 ms
Memory 4992 KB

Compile Error

./Main.c: In function ‘flush’:
./Main.c:44:3: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
   write(STDOUT_FILENO, buf, bufe-buf);
   ^

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 00_sample_01.txt
All 100 / 100 00_sample_01.txt, subtask_01_01.txt, subtask_01_02.txt, subtask_01_03.txt, subtask_01_04.txt, subtask_01_05.txt, subtask_01_06.txt, subtask_01_07.txt, subtask_01_08.txt, subtask_01_09.txt, subtask_01_10.txt, subtask_01_11.txt, subtask_01_12.txt, subtask_01_13.txt, subtask_01_14.txt, subtask_01_15.txt, subtask_01_16.txt, subtask_01_17.txt, subtask_01_18.txt
Case Name Status Exec Time Memory
00_sample_01.txt 1 ms 512 KB
subtask_01_01.txt 4 ms 4224 KB
subtask_01_02.txt 1 ms 512 KB
subtask_01_03.txt 4 ms 4992 KB
subtask_01_04.txt 6 ms 4608 KB
subtask_01_05.txt 1 ms 768 KB
subtask_01_06.txt 1 ms 768 KB
subtask_01_07.txt 6 ms 4608 KB
subtask_01_08.txt 6 ms 4608 KB
subtask_01_09.txt 1 ms 512 KB
subtask_01_10.txt 1 ms 512 KB
subtask_01_11.txt 4 ms 4736 KB
subtask_01_12.txt 6 ms 4608 KB
subtask_01_13.txt 5 ms 4352 KB
subtask_01_14.txt 1 ms 512 KB
subtask_01_15.txt 4 ms 4608 KB
subtask_01_16.txt 6 ms 4608 KB
subtask_01_17.txt 6 ms 4096 KB
subtask_01_18.txt 6 ms 4096 KB