結果
| 問題 | No.1293 2種類の道路 |
| コンテスト | |
| ユーザー |
👑 tails
|
| 提出日時 | 2020-11-24 01:14:09 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 20 ms / 2,000 ms |
| コード長 | 1,475 bytes |
| 記録 | |
| コンパイル時間 | 1,520 ms |
| コンパイル使用メモリ | 32,640 KB |
| 実行使用メモリ | 12,680 KB |
| 最終ジャッジ日時 | 2024-07-23 18:19:07 |
| 合計ジャッジ時間 | 3,835 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
コンパイルメッセージ
main.c:55:1: warning: return type defaults to 'int' [-Wimplicit-int]
55 | main(){
| ^~~~
main.c: In function 'main':
main.c:82:9: warning: implicit declaration of function 'write' [-Wimplicit-function-declaration]
82 | write(1,wbuf,wp-wbuf);
| ^~~~~
main.c:83:9: warning: implicit declaration of function '_exit'; did you mean '_Exit'? [-Wimplicit-function-declaration]
83 | _exit(0);
| ^~~~~
| _Exit
ソースコード
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
char*mmap();
#define RD(v) int v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;}
#define WTHI(v) {long _z=v,_n=0,_d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(long*)wp=_d;wp+=_n;}
#define WTLO(v) {long _z=v,_n=8,_d=0;while(_d=_d<<8|0x30|_z%10,_z/=10,--_n);*(long*)wp=_d;wp+=8;}
#define WT(v) if(v>=100000000){WTHI(v/100000000);WTLO(v);}else{WTHI(v);}
#define HASH_BITS 20
long hash[1<<HASH_BITS];
int hash_add(long x){
int h=x&(1<<HASH_BITS)-1;
while(1){
if(hash[h]==0){
hash[h]=x;
return 1;
}
if(hash[h]==x){
return 0;
}
h=h+1&(1<<HASH_BITS)-1;
}
}
int ufbuf[200002];
void uf_init(){
for(int i=0;i<200002;++i){
ufbuf[i]=-1;
}
}
int uf_find(int a){
int b;
int t=a;
while(b=ufbuf[t],b>=0) t=b;
while(b=ufbuf[a],b>=0) ufbuf[a]=t,a=b;
return t;
}
void uf_unite(int a,int b){
a=uf_find(a);
b=uf_find(b);
if(a!=b){
if(ufbuf[a]<ufbuf[b]){
ufbuf[a]+=ufbuf[b];
ufbuf[b]=a;
}else{
ufbuf[b]+=ufbuf[a];
ufbuf[a]=b;
}
}
}
main(){
uf_init();
char*rp=mmap(0l,7l*400004,1,2,0,0ll);
RD(n);
RD(v);
RD(w);
for(int i=0;i<v;++i){
RD(a);
RD(b);
uf_unite(a,b);
}
for(int i=0;i<w;++i){
RD(a);
RD(b);
uf_unite(a+n,b+n);
}
long z=-n;
for(int i=1;i<=n;++i){
int a=uf_find(i);
int b=uf_find(i+n);
long x=a+(1l<<32|307)*(b-n);
if(hash_add(x)){
z+=(long)ufbuf[a]*(long)ufbuf[b];
}
}
char wbuf[16],*wp=wbuf;
WT(z);
write(1,wbuf,wp-wbuf);
_exit(0);
}
tails