Submission #1030612

# Submission time Handle Problem Language Result Execution time Memory
1030612 2024-07-22T07:37:17 Z sleepntsheep Graph (BOI20_graph) C
Compilation error
0 ms 0 KB
#include<stdio.h>
#include<stdlib.h>
#include<vector>
int C(const void*a,const void*b){return(int)(*(const double*)a-*(const double*)b);}
#define N 100001
#define M 400001
double a(double x){return x<0?-x:x;}
int n,m,head[N],fr[M],to[M],nxt[M],col[M],ii,vis[N],aa[N],bb[N],grp[N],got[N],eo[N<<1];
double *eh[N<<1];
void push(int i,int j){
    int o=eo[i]++;
    if(!o)eh[i]=(double*)malloc(2*sizeof**eh);
    else if(!(o&o-1))eh[i]=(double*)realloc(eh[i],2*o*sizeof**eh);
    eh[i][o]=j;
}
double xx[N];

void link(int u,int v,int c){
    int i=++ii;
    to[i]=v;
    fr[i]=u;
    col[i]=c;
    nxt[i]=head[u];
    head[u]=i;
}

void dfs(int u,int a,int b,int cp){
    if(vis[u]){
        if(a==aa[u]&&b!=bb[u]) exit(puts("NO")*0);
        return;
    }
    grp[u]=cp;
    push(cp+N,u);
    double want=-1.0f*b/a;
    push(cp,want);
    vis[u]=1,aa[u]=a,bb[u]=b;
    for(int j=head[u];j;j=nxt[j])
        dfs(to[j],-a,col[j]-b,cp);
}

int main(){
    scanf("%d%d",&n,&m);
    for(int u,v,c,i=0;i<m;++i)scanf("%d%d%d",&u,&v,&c),link(u,v,c),link(v,u,c);
    for(int i=1;i<=n;++i)
        if(!vis[i])
            dfs(i,1,0,i);

    for(int j=1;j<ii;++j){
        double a1=aa[fr[j]]+aa[to[j]],b1=bb[fr[j]]+bb[to[j]];
        if(a1==0&&b1!=col[j])exit(puts("NO")*0);
    }

    for(int i=1;i<=n;++i){
        if(got[grp[i]])continue;
        double l=-1e5,r=1e5;
        int sz=eo[grp[i]+N];
        qsort(eh[grp[i]],eo[grp[i]],**eh,C);
        xx[grp[i]]=eh[grp[i]][(eo[grp[i]]+1)/2];
    }

    puts("YES");
    for(int i=1;i<=n;++i) printf("%.3f ",aa[i]*xx[grp[i]]+bb[i]);
}

Compilation message

Graph.c:3:9: fatal error: vector: No such file or directory
    3 | #include<vector>
      |         ^~~~~~~~
compilation terminated.