又遭遇了Pascal版AC而翻译成C++则TLE。[gview file="http://d.ream.at/wp-content/attachments/sgu122.pdf" ]


//list版 TLE on test 20
#include
#include #include
using namespace std;

int main() {
list ninlist,plist;
bool map[1001][1001]={{0}};
char rbuf[5001];
int n;
gets(rbuf); sscanf(rbuf,"%d",&n);
for (int i=1;i<=n;++i) { ninlist.push_back(i); int j=0,pos=0; gets(rbuf); while (sscanf(rbuf+pos,"%d",&j)!=EOF) { map[i][j]=map[j][i]=true; while (rbuf[pos]>32) pos++;
while (rbuf[pos]==32) pos++;
}
}
plist.splice(plist.end(),ninlist,ninlist.begin());
while (ninlist.size()) {
for (bool find=true;find;) {
find=false;
for (list::iterator i=ninlist.begin();i!=ninlist.end();++i) if (map[*i][plist.front()] || map[*i][plist.back()]) {
find=true;
plist.splice(map[*i][plist.front()]?plist.begin():plist.end(),ninlist,i);
break;
}
}
for (list::iterator j=plist.begin(),i=j++;j!=plist.end();++i,++j) if (map[*i][plist.back()] && map[*j][plist.front()]) {
reverse(j,plist.end()); break;
}
if (ninlist.size()) for (list::iterator i=plist.begin();i!=plist.end();++i) if (map[*i][ninlist.front()]) {
plist.splice(plist.end(),plist,plist.begin(),i);
plist.splice(plist.begin(),ninlist,ninlist.begin());
break;
}
}
plist.splice(plist.end(),plist,plist.begin(),find(plist.begin(),plist.end(),1));
for (list::iterator i=plist.begin();i!=plist.end();++i) printf("%d ",*i);
printf("1\n");
return 0;
}


//pas数组版 AC
program sgu122;
var
map:array[1..1000,1..1000] of boolean;
plist,buf:array[1..1000] of longint;
ninlist:array[1..1000] of boolean;
n,i,j,base,num:longint;
find:boolean;

procedure reverse(i,j:longint);
var
k:longint;
begin
move(plist[i],buf[1],(j-i+1)*sizeof(longint));
for k:=i to j do plist[k]:=buf[j-k+1];
end;

begin
readln(n);
fillchar(map,sizeof(map),false);
fillchar(ninlist,sizeof(ninlist),true);
for i:=1 to n do begin
while not eoln do begin
read(j);
map[i,j]:=true; map[j,i]:=true;
end;
readln;
end;
num:=1; plist[1]:=1; ninlist[1]:=false;
while num


//cpp数组版 TLE on test 20
#include
#include
using namespace std;

int n,num=0;
int plist[1001]={0},buf[1001];
char rbuf[5001];
bool ninlist[1001];
bool map[1001][1001]={{0}};

int main() {
gets(rbuf); sscanf(rbuf,"%d",&n);
for (int i=1;i<=n;++i) { ninlist[i]=true; int j=0,pos=0; gets(rbuf); while (sscanf(rbuf+pos,"%d",&j)!=EOF) { map[i][j]=map[j][i]=true; while (rbuf[pos]>32) pos++;
while (rbuf[pos]==32) pos++;
}
}
plist[++num]=1; ninlist[1]=false;
while (num