Submission #1177720


Source Code Expand

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

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

__attribute__((target("arch=sandybridge")))
void readall(){
  int k, t = 0;
  while((k=read(STDIN_FILENO, ibuf+t, sizeof(ibuf)-t))>0) t += k;
}

__attribute__((target("arch=sandybridge")))
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;

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

__attribute__((target("arch=sandybridge")))
void flush(){
  write(STDOUT_FILENO, buf, bufe-buf);
}

int tree[100000];

__attribute__((target("arch=sandybridge")))
int root(int i){
  if(tree[i]<0) return i;
  return tree[i] = root(tree[i]);
}

__attribute__((target("arch=sandybridge")))
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;
}

__attribute__((target("arch=sandybridge")))
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 1623 Byte
Status AC
Exec Time 7 ms
Memory 4352 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 Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 1
AC × 19
Set Name Test Cases
Sample 00_sample_01.txt
All 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 AC 1 ms 512 KB
subtask_01_01.txt AC 3 ms 2688 KB
subtask_01_02.txt AC 1 ms 512 KB
subtask_01_03.txt AC 4 ms 3328 KB
subtask_01_04.txt AC 6 ms 4352 KB
subtask_01_05.txt AC 1 ms 768 KB
subtask_01_06.txt AC 1 ms 768 KB
subtask_01_07.txt AC 6 ms 3456 KB
subtask_01_08.txt AC 6 ms 4352 KB
subtask_01_09.txt AC 1 ms 512 KB
subtask_01_10.txt AC 1 ms 512 KB
subtask_01_11.txt AC 4 ms 2944 KB
subtask_01_12.txt AC 6 ms 4352 KB
subtask_01_13.txt AC 5 ms 3200 KB
subtask_01_14.txt AC 1 ms 512 KB
subtask_01_15.txt AC 4 ms 3200 KB
subtask_01_16.txt AC 6 ms 4352 KB
subtask_01_17.txt AC 7 ms 3840 KB
subtask_01_18.txt AC 7 ms 3840 KB