Language: C

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <algorithm>
#include <queue>
#define clr(a,b) memset(a,b,sizeof(a))
#define forn(i,n) for(int i=0;i<n;i++)
#define ll long long

using namespace std;

const double Ka=1000, Kb=1000, Kc=1000;
const double eps=1e-4;

typedef int typef;
typedef double typec;
const int N=50,M=100000;
const typef inff=0x3f3f3f3f;
const typec infc=1E9;

int flow[N][N];
double cost[N][N];
int flag[N],used[N];
int dis[N][N];
int ans[100010];

struct MinCostMaxFlow
{
    int e, ev[M], nxt[M], fa[M], pre[M], head[N];
    typec cost[M], dist[N];
    typef cap[M],icap[M];
    int pnt[N], road[N], q[N], bg, ed;
    bool vis[N];
    void init()
    {
        e = 0;
        clr(head, -1);clr(pre, -1);
    }
    void sa_init(){
        for(int i=0;i<e;i++)
            cap[i]=icap[i];
    }
    void addedge(int u, int v, typef f, typec c)   //u->v flow=f, cost=c
    {
        fa[e]=u;ev[e]=v;icap[e]=cap[e]=f;cost[e]=c;nxt[e]=head[u];pre[head[u]]=e;head[u]=e++;
        fa[e]=v;ev[e]=u;icap[e]=cap[e]=0;cost[e]=-c;nxt[e]=head[v];pre[head[v]]=e;head[v]=e++;
    }
    void deledge(int u,int v,int id){
        if(~pre[id]){
            nxt[pre[id]]=nxt[id];
            pre[nxt[id]]=pre[id];
        }
        else{
            head[u]=nxt[id];
            pre[nxt[id]]=-1;
        }
    }
    bool spfa(int s, int t, int n)
    {
        forn (i, n) dist[i] = infc, vis[i] = 0;
        bg = ed = dist[s] = 0;
        pnt[s] = s;
        q[ed++] = s;
        while (bg != ed)
        {
            int u = q[bg++];
            vis[u] = 0;
            if (bg == N) bg = 0;
            for (int i = head[u]; ~i; i = nxt[i])
            {
                if (cap[i] <= 0)continue;
                int v = ev[i];
                if (dist[v] > dist[u] + cost[i] + eps)
                {
                    dist[v] = dist[u] + cost[i];
                    pnt[v] = u;
                    road[v] = i;
                    if (!vis[v])
                    {
                        q[ed++] = v;
                        vis[v] = 1;
                        if(ed == N)ed = 0;
                    }
                }
            }
        }
        return fabs(dist[t]-infc)>eps;
    }
    void mincost(int s, int t, int n, typef &f, typec &c)
    {
        c = f = 0;
        while(spfa(s, t, n))
        {
            typef minf = inff;
            for(int u = t; u != s; u = pnt[u])
                minf = min(minf, cap[road[u]]);
            for(int u = t; u != s; u = pnt[u])
            {
                cap[road[u]] -= minf;
                cap[road[u] ^ 1] += minf;
            }
            f += minf;
            c += minf * dist[t];
        }
    }
}g,g1;

double costa(double Ka,int x){
    if(x<=30) return 1.0*Ka/45.34;
    double up,down,tmp;
    up=-0.51*x+60.6404;
    down=-0.51*x+61.1504;
    tmp=-1.0*Ka/0.51*log(up/down);
    return tmp;
}

double costb(double Kb,int x){
    if(x<=10) return 1.0*Kb/54.14;
    double up,down,tmp;
    up=-0.45*x+58.6404;
    down=-0.45*x+59.0904;
    tmp=-1.0*Kb/0.45*log(up/down);
    return tmp;
}

double costc(double Kc,double x){
    double y=0.5*x+3.4;
    double up,down,tmp;
    up=10000.0*y*y-172200*y+369430;
    down=10000.0*y*y-172200*y+481396;
    tmp=0.0893131*Kc*log(up/down);
    return tmp;
}

void floyed(int tot){
    for(int k=0;k<tot;k++)
        for(int i=0;i<tot;i++)
            for(int j=0;j<tot;j++)
                dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
}

int main(){
#ifdef WAR10CK
    freopen("in","r",stdin);
    freopen("out","w",stdout);
#endif
    int tot,u,v,f,x,y;
    double c;
    char type[5];
    g.init();clr(cost,0);clr(flow,0);clr(flag,0);clr(used,0);clr(dis,0x3f);
    scanf("%d",&tot);
    scanf("%d",&x);
    for(int i=0;i<x;i++){
        scanf("%d",&y);
        used[y]=1;
    }
    scanf("%d",&x);
    for(int i=0;i<x;i++){
        scanf("%d",&y);
        flag[y]=1;
    }
    scanf("%d",&x);
    for(int i=0;i<x;i++){
        scanf("%d",&y);
        flag[y]=2;
    }
    while(~scanf("%d%d%s",&u,&v,type)){
        if(flag[u] && flag[v]){
            dis[u][v]=dis[v][u]=1;
        }
        if(type[0]=='x'){
            scanf("%d",&f);
            g.addedge(u,v,f,0);
        }
        else if(type[0]=='y'){
            scanf("%d",&f);
            g.addedge(u,v,f,0);
        }
        else if(type[0]=='a'){
            for(int i=1;i<=118;i++){
                if(u==16 && v==22){
                    g.addedge(u,v,100,costa(20*Ka,i));
                    g.addedge(v,u,100,costa(20*Ka,i));
                    continue;
                }
                if(u==31 && v==32){
                    g.addedge(u,v,100,costa(2*Ka,i));
                    g.addedge(v,u,100,costa(2*Ka,i));
                    continue;
                }
                if(u==25 && v==29){
                    g.addedge(u,v,100,costa(2*Ka,i));
                    g.addedge(v,u,100,costa(2*Ka,i));
                    continue;
                }
                if(u==3 && v==25){
                    g.addedge(u,v,100,costa(2*Ka,i));
                    g.addedge(v,u,100,costa(2*Ka,i));
                    continue;
                }
                g.addedge(u,v,100,costa(Ka,i));
                g.addedge(v,u,100,costa(Ka,i));
//                printf("%d\n",costa(i));
            }
        }
        else if(type[0]=='b'){
            for(int i=1;i<=60;i++){
                if((u==11 && v==30) || (u==15 && v==30)){
                    g.addedge(u,v,100,costb(2*Kb,i));
                    g.addedge(v,u,100,costb(2*Kb,i));
                    continue;
                }
                if(u==22 && v==24){
                    g.addedge(u,v,100,costb(10*Kb,i));
                    g.addedge(v,u,100,costb(10*Kb,i));
                    continue;
                }
                if(u==17 && v==24){
                    g.addedge(u,v,100,costb(2*Kb,i));
                    g.addedge(v,u,100,costb(2*Kb,i));
                    continue;
                }

                g.addedge(u,v,100,costb(Kb,i));
                g.addedge(v,u,100,costb(Kb,i));
//                printf("%d\n",costb(i));
            }
        }
        else if(type[0]=='c'){
            for(int i=1;i<=20;i++){
                g.addedge(u,v,100,costc(Kc,i));
                g.addedge(v,u,100,costc(Kc,i));
//                printf("%d : %lf\n",i,costc(Kc,i));
            }
        }
    }
    floyed(tot);
    double T=10,r=0.95;
    int cnt=4;//隶ー蠖穂ク企擇逧?膚蝨域焚驥?    while(T >= 1){
        srand((unsigned) time(NULL));
        for(int i=0;i<tot;i++){
            if(used[i]){
            //sa init
                //tmp
                int tmp,tcnt;
                do{
                    tmp=rand()%tot;
                }while(!flag[tmp] && dis[i][tmp]>T);
                //cnt
                if(flag[tmp]==1 && flag[i]==2 && !used[tmp]){
                    if(cnt==5) continue;
                    else tcnt=cnt+1;
                }
                else if(flag[tmp]==2 && flag[i]==1 && !used[tmp]){
                    if(cnt==4) continue;
                    else tcnt=cnt-1;
                }
                else tcnt=cnt;
                //edge
                g1=g;
                if(!used[tmp]){
                    for(int j=g1.head[33];~j;j=g1.nxt[j]){
                        if(g1.ev[j]==i){
                            g1.addedge(tmp,33,g1.icap[j^1],0);
                            g1.deledge(g1.fa[j],g1.ev[j],j);
                            g1.deledge(g1.fa[j^1],g1.ev[j^1],j^1);
                        }
                    }
                }
                else{
                    int minn=min(i,tmp),maxn=max(i,tmp);
                    int tcap;
                    for(int j=g1.head[33];~j;j=g1.nxt[j]){
                        if(g1.ev[j]==minn){
                            g1.addedge(maxn,33,g1.icap[j^1],0);
                            g1.deledge(g1.fa[j],g1.ev[j],j);
                            g1.deledge(g1.fa[j^1],g1.ev[j^1],j^1);
                        }
                        else if(g1.ev[i]==maxn){
                            g1.addedge(minn,33,g1.icap[j^1],0);
                            g1.deledge(g1.fa[j],g1.ev[j],j);
                            g1.deledge(g1.fa[j^1],g1.ev[j^1],j^1);
                        }
                    }
                }
            //sa
                int f,f1;double c,c1;
                g.sa_init();g1.sa_init();
                g.mincost(0,33,tot,f,c);g1.mincost(0,33,tot,f1,c1);
                double dE=c-c1;
                if(dE>=0){
                    g=g1;cnt=tcnt;
                    if(used[tmp]) continue;
                    else used[tmp]=true,used[i]=false;
                }
                else{
                    if(exp(dE/T) > (double)rand()/INT_MAX){
                        g=g1;cnt=tcnt;
                        if(used[tmp]) continue;
                        else used[tmp]=true,used[i]=false;
                    }
                }
            //update
                printf("T=%-10.3lf flow=%-10d cost=%lf\n",T,f,c);

            }
        }

        T *= r;
    }
    for(int i=0;i<tot;i++)
        if(used[i])
            printf("%d ",i);
    puts("");
    for(int i=0;i<g.e;i+=2){
//        if(g.cap[i]>0&&g.cap[i]<100) printf("go\n");
//        if(g.fa[i]==0 || g.ev[i]==0){
//            flow[g.fa[i]][g.ev[i]]+=g.cap[i];
//            continue;
//        }
        flow[g.fa[i]][g.ev[i]]+=100-g.cap[i];
        cost[g.fa[i]][g.ev[i]]+=(100-g.cap[i])*g.cost[i];
    }
    for(int i=1;i<tot-1;i++)
        for(int j=i;j<tot-1;j++){
            if(flow[i][j]==flow[j][i] && flow[i][j]){
                printf("i:%d j:%d\n",i,j);
            }
            if(flow[i][j]>flow[j][i]){
                flow[i][j]-=flow[j][i];
                cost[i][j]=cost[i][j]+cost[j][i];
                if(flow[i][j] || cost[i][j]){
                    printf("%d->%d %d %lf\n",i,j,flow[i][j],cost[i][j]);
                }
            }
            else{
                flow[i][j]=flow[j][i]-flow[i][j];
                cost[i][j]=cost[j][i]+cost[i][j];
                if(flow[i][j] || cost[i][j]){
                    printf("%d->%d %d %lf\n",j,i,flow[i][j],cost[i][j]);
                }
            }
//            if(flow[i][j] && flow[j][i]){
//                printf("%d %d %d %d\n",i,j,flow[i][j],flow[j][i]);
//            }
        }

    return 0;
}

Compiler output:
main.c:6:10: fatal error: algorithm: No such file or directory
    6 | #include <algorithm>
      |          ^~~~~~~~~~~
compilation terminated.