QOJ.ac
QOJ
ID | 提交记录ID | 题目 | Hacker | Owner | 结果 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|
#968 | #635775 | #9453. Graph Generator | lgvc | ucup-team5177 | Failed. | 2024-10-13 19:37:55 | 2024-10-13 19:54:56 |
詳細信息
Extra Test:
Accepted
time: 581ms
memory: 18588kb
input:
20 100000 99999 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 ...
output:
Yes 100000 0 99999 0 99998 0 99997 0 99996 0 99995 0 99994 0 99993 0 99992 0 99991 0 99990 0 99989 0 99988 0 99987 0 99986 0 99985 0 99984 0 99983 0 99982 0 99981 0 99980 0 99979 0 99978 0 99977 0 99976 0 99975 0 99974 0 99973 0 99972 0 99971 0 99970 0 99969 0 99968 0...
result:
ok 20 cases passed
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#635775 | #9453. Graph Generator | ucup-team5177# | TL | 960ms | 187816kb | C++23 | 3.1kb | 2024-10-12 20:55:32 | 2024-10-14 16:54:19 |
answer
#include <bits/stdc++.h>
static char buf[1000000],*paa=buf,*pd=buf;
static char buf2[1000000],*pp=buf2;
#define getchar() paa==pd&&(pd=(paa=buf)+fread(buf,1,1000000,stdin),paa==pd)?EOF:*paa++
inline void pc(char ch){
if(pp-buf2==1000000) fwrite(buf2,1,1000000,stdout),pp=buf2;
*pp++=ch;
}
inline void pcc(){
fwrite(buf2,1,pp-buf2,stdout);
pp=buf2;
}
inline int read(void){
int w=1;
register int x(0);register char c(getchar());
while(c<'0'||c>'9'){if(c=='-') w=-1;c=getchar();}
while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
return w*x;
}
void write(int x){
static int sta[20];
int top=0;
do{
sta[top++]=x%10,x/=10;
}while(x);
while(top) pc(sta[--top]+48);
}
void we(int x){
write(x);
pc('\n');
}
int T,N,M,ans[100009],dg[100009],pa[100009],id;
struct n_t{
int a,b;
};
std::vector<int> as[100009];
inline int fr(int x) {
while(x!=pa[x]) x=pa[x]=pa[pa[x]];
return x;
}
inline void co(int x,int y) {
x=fr(x),y=fr(y);
if(x!=y) pa[x]=y;
}
bool cmp1(int m,int n) {
return fr(m)<fr(n);
}
bool cmp2(n_t m,n_t n) {
return fr(m.a)<fr(n.a);
}
bool sv(std::vector<int> x,std::vector<n_t> y) {
if(x.size()==1) {
ans[++id]=x[0];
as[id].clear();
return 1;
}
for(int i=0;i<x.size();i++) {
// printf("%d ",x[i]);
dg[x[i]]=0;
pa[x[i]]=x[i];
}
for(int i=0;i<y.size();i++) {
// printf("| %d %d",y[i].a,y[i].b);
dg[y[i].a]++;
dg[y[i].b]++;
}
// printf("\n");
int pt=0;
for(int i=0;i<x.size();i++) {
if(dg[x[i]]==x.size()-1) {
pt=x[i];
break;
}
}
if(pt==0) {
return 0;
}
ans[++id]=pt;as[id].clear();
std::vector<n_t> yy;
std::vector<int> xx,rt,rt2;
for(int i=0;i<y.size();i++) {
if(y[i].a==pt||y[i].b==pt) continue;
yy.push_back(y[i]);
co(y[i].a,y[i].b);
}
y=yy;
for(int i=0;i<x.size();i++) {
if(x[i]!=pt) xx.push_back(x[i]);
}
x=xx;
std::sort(y.begin(),y.end(),cmp2);
std::sort(x.begin(),x.end(),cmp1);
int i1=0,i2=0;
int cur=id;
for(int i=0;i<x.size();i++) {
rt.push_back(fr(x[i]));
}
for(int i=0;i<y.size();i++) {
rt2.push_back(fr(y[i].a));
}
for(int i=0;i<x.size();i++) {
if(rt[i]!=x[i]) continue;
int st=i1;
while(i1<x.size()&&rt[i1]<=x[i]) {
i1++;
}
int ed=i1-1;
std::vector<int> xa;
std::vector<n_t> ya;
for(int j=st;j<=ed;j++) xa.push_back(x[j]);
st=i2;
while(i2<y.size()&&rt2[i2]<=x[i]) {
if(rt2[i2]<x[i]) st=i2+1;
i2++;
}
ed=i2-1;
for(int j=st;j<=ed;j++) ya.push_back(y[j]);
as[cur].push_back(x[i]);
if(!sv(xa,ya)) return 0;
}
return 1;
}
signed main(void) {
T=read();
while(T--) {
N=read();M=read();
std::vector<int> x;
std::vector<n_t> y;
x.push_back(N+1);
for(int i=1;i<=N;i++) x.push_back(i),y.push_back((n_t){i,N+1});
for(int i=1;i<=M;i++) {
int a=read(),b=read();
y.push_back((n_t){a,b});
}
id=0;
if(!sv(x,y)) {
pc('N');pc('o');pc('\n');
continue;
}
pc('Y');pc('e');pc('s');pc('\n');
for(int i=id;i>=2;i--) {
write(ans[i]),pc(' ');
write(as[i].size()),pc(' ');
for(int j=0;j<as[i].size();j++) write(as[i][j]),pc(' ');
pc('\n');
}
}
pcc();
}