QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#426375#6329. Colorful Graphzyz07Compile Error//C++172.1kb2024-05-31 09:31:332024-05-31 09:31:33

Judging History

你现在查看的是最新测评结果

  • [2024-05-31 09:31:33]
  • 评测
  • [2024-05-31 09:31:33]
  • 提交

answer

#include <bits/stdc++.h>
#include <templates/max_flow>
using namespace std;
#define For(Ti,Ta,Tb) for(auto Ti=(Ta);Ti<=(Tb);++Ti)
#define Dec(Ti,Ta,Tb) for(auto Ti=(Ta);Ti>=(Tb);--Ti)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define range(Tx) begin(Tx),end(Tx)
using ll=long long;
const int N=7005;
int n,m,tot,bel[N],ans[N];
vector<int> g[N],scc[N],g2[N];
struct{
	int dfn[N],low[N],dfx,stk[N],top,vis[N];
	void tarjan(int u){
		low[u]=dfn[u]=++dfx;
		stk[++top]=u;
		vis[u]=1;
		for(int v:g[u]){
			if(!dfn[v]){
				tarjan(v);
				low[u]=min(low[u],low[v]);
			}else if(vis[v]){
				low[u]=min(low[u],dfn[v]);
			}
		}
		if(dfn[u]==low[u]){
			++tot;
			for(int v=0;v!=u;){
				v=stk[top--];
				bel[v]=tot;
				scc[tot].push_back(v);
				vis[v]=0;
			}
		}
	}
	void operator()(){
		For(u,1,n){
			if(!dfn[u]){
				tarjan(u);
			}
		}
	}
}tarjan;
void color(int u,int c){
	for(int v:scc[u]){
		ans[v]=c;
	}
	for(int v:g2[u]){
		if(!ans[scc[v][0]]){
			color(v,c);
		}
	}
}
int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	cin>>n>>m;
	For(i,1,m){
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
	}
	tarjan();
	MaxFlow<int> f(tot*2+3);
	int s=f.n-2,t=f.n-1;
	For(u,1,tot){
		f.add_edge(s,u,1);
		f.add_edge(u+tot,t,1);
		for(int v:scc[u]){
			for(int x:g[v]){
				f.add_edge(u,bel[x]+tot,1);
				f.add_edge(u+tot,bel[x]+tot,f.Inf);
			}
		}
	}
	f.flow(s,t);
	vector<int> poi;
	for(int i:f.g[s]){
		auto [u,w]=f.e[i];
		if(!w){
			poi.push_back(u);
		}
	}
	for(int s:poi){
		vector<int> vis(f.n);
		queue<int> q;
		q.push(s);
		while(q.size()){
			int u=q.front();
			q.pop();
			bool flg=0;
			for(int i:f.g[u]){
				int v=f.e[i].v;
				if(!vis[v]&&f.e[i^1].w){
					if(v==t){
						flg=1;
						f.e[i].w++;
						f.e[i^1].w--;
						break;
					}
					vis[v]=1;
					q.push(v);
				}
			}
			if(flg){
				g2[s].push_back(u-tot);
				g2[u-tot].push_back(s);
				break;
			}
		}
	}
	int cur=0;
	For(u,1,tot){
		if(!ans[scc[u][0]]){
			color(u,++cur);
		}
	}
	For(u,1,n){
		cout<<ans[u]<<" \n"[u==n];
	}
	return 0;
}

Details

answer.code:2:10: fatal error: templates/max_flow: No such file or directory
    2 | #include <templates/max_flow>
      |          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.