QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#527661#6659. 외곽 순환 도로 2NianFengCompile Error//C++142.6kb2024-08-22 18:04:342024-08-22 18:04:34

Judging History

你现在查看的是测评时间为 2024-08-22 18:04:34 的历史记录

  • [2024-08-26 15:53:31]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:31ms
  • 内存:33824kb
  • [2024-08-22 18:04:34]
  • 评测
  • [2024-08-22 18:04:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll long long
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 1e18
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
ll n,m=0,head[100010],cnt=0,L[100010],R[100010],w[100010],f[100010][2][2][2];
struct node{
	ll nxt,to,w;
}e[100010];
void add(ll u,ll v,ll ww){
	e[++cnt].nxt=head[u];
	e[cnt].to=v;
	e[cnt].w=ww;
	head[u]=cnt;
}
void dfs(ll u){
	go(u){
		ll v=e[i].to;
		dfs(v);
		if(!L[u]) L[u]=L[v];
		R[u]=R[v];
	}
	if(!L[u]) L[u]=R[u]=++m;
}
void dfss(ll u){
	fr(x,0,1) fr(y,0,1) fr(z,0,1) f[u][x][y][z]=inf;
	go(u){
		ll v=e[i].to;
		dfss(v);
	}
	if(!head[u]){
		f[u][0][0][0]=f[u][1][1][1]=0;
		return;
	}
	ll lst[2][2];
	fr(col,0,1){
		go(u){
			ll v=e[i].to;
			fr(x,0,1) fr(y,0,1) lst[x][y]=f[u][col][x][y];
			fr(x,0,1) fr(y,0,1) f[u][col][x][y]=inf;
			if(i==head[u]){
				fr(vcol,0,1) fr(x,0,1) fr(y,0,1) f[u][col][x][y]=min(f[u][col][x][y],f[v][vcol][x][y]+(col==vcol)*e[i].w);
				continue;
			}
			fr(x,0,1) fr(y,0,1) fr(vcol,0,1) fr(xx,0,1) fr(yy,0,1) f[u][col][x][yy]=min(f[u][col][x][yy],lst[x][y]+f[v][vcol][xx][yy]+(y==xx)*w[L[v]-1]+(vcol==col)*e[i].w);
		}
	}
}
ll place_police(vector<int> P,vector<ll> C,vector<ll> W){
	n=P.size()+1;
	pfr(i,n,2) add(P[i-2]+1,i,C[i-2]);
	dfs(1);
	fr(i,1,m) w[i]=W[i-1];
	dfss(1);
	ll ans=inf;
	fr(col,0,1) fr(x,0,1) fr(y,0,1) ans=min(ans,f[1][col][x][y]+(x==y)*w[m]);
    return ans;
}
/*
妙妙题
删成没有奇环很难刻画,考虑没有奇环就是二分图,可以黑白染色。
*/

Details

cc1plus: fatal error: implementer.cpp: No such file or directory
compilation terminated.