Pagini recente » Cod sursa (job #2325930) | Cod sursa (job #2723268) | Cod sursa (job #454681) | Cod sursa (job #2433099) | Cod sursa (job #541481)
Cod sursa(job #541481)
#include <cstdio>
#include <algorithm>
using namespace std;
FILE *f,*g;
typedef short Huge[18];
int n,m,i;
struct cp{int x,y,z; Huge c1,c2;} v[200100];
#define cat(c) while(c==' ') fscanf(f,"%c",&c);
bool bif[210000];
void MultHuge(Huge A, Huge B, Huge C)
{ int i,j,T=0;
C[0]=A[0]+B[0]-1;
for (i=1;i<=A[0]+B[0];) C[i++]=0;
for (i=1;i<=A[0];i++)
for (j=1;j<=B[0];j++)
C[i+j-1]+=A[i]*B[j];
for (i=1;i<=C[0];i++)
{ T=(C[i]+=T)/10;
C[i]%=10;
}
if (T) C[++C[0]]=T;
}
int Sgn(Huge H1, Huge H2) {
while (H1[0] && !H1[H1[0]]) H1[0]--;
while (H2[0] && !H2[H2[0]]) H2[0]--;
if (H1[0] < H2[0]) {
return -1;
} else if (H1[0] > H2[0]) {
return +1;
}
for (int i = H1[0]; i > 0; --i) {
if (H1[i] < H2[i]) {
return -1;
} else if (H1[i] > H2[i]) {
return +1;
}
}
return 0;
}
void intors(Huge A) {
int i,aux;
for (i=1;i<=A[0]/2;i++) {
aux=A[i];
A[i]=A[A[0]+i-1];
A[A[0]+i-1]=aux;
}
}
bool cmp(cp i , cp j) {
int a,b;
a=Sgn(i.c1,j.c1);
if (a!=0) {
return (a==-1);
}
else {
b=Sgn(i.c2,j.c2);
return (b==1);
}
}
int main() {
f=fopen("lazy.in","r");
g=fopen("lazy.out","w");
fscanf(f,"%d%d",&n,&m);
char c;
for (i=1;i<=m;i++) {
v[i].z=i;
fscanf(f,"%d%d",&v[i].x,&v[i].y);
fscanf(f,"%c",&c);
cat(c);
while (c>='0' && c<='9') {
v[i].c1[++v[i].c1[0]]=c-'0';
fscanf(f,"%c",&c);
}
intors(v[i].c1);
cat(c);
while (c>='0' && c<='9') {
v[i].c2[++v[i].c2[0]]=c-'0';
fscanf(f,"%c",&c);
}
intors(v[i].c2);
//MultHuge(v[i].c1,v[i].c2,v[i].c3);
}
stable_sort(v+1,v+n+1,cmp);
i=1;
int con=0;
while (i<=m && con<n-1) {
if (bif[v[i].x]==false || bif[v[i].y]==false) {
con++;
bif[v[i].x]=true;
bif[v[i].y]=true;
fprintf(g,"%d",v[i].z);
if (con!=n-1) fprintf(g,"\n");
}
i++;
}
fclose(g);
return 0;
}