QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#83479 | #3249. 分组作业 | fengyuyue | WA | 21ms | 5484kb | C++14 | 4.4kb | 2023-03-02 09:41:57 | 2023-03-02 09:41:59 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define gc getchar
#define pc putchar
#define pii pair<int,int>
#define pil pair<int,long long>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define For(i,l,r) for(int i=(l);i<=(r);i++)
#define IFor(i,r,l) for(int i=(r);i>=(l);i--)
#define for_son(u) for(int e=head[u];e;e=nxt[e])
#define eps (1e-8)
#define ll_INF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
using namespace std;
char aa;
namespace ljh
{
namespace IO
{
// const int SIZ=1<<20;
// char ibuf[SIZ],*p1,*p2,obuf[SIZ],*p3=obuf;
// #define gc() (p1==p2&&(p2=(p1=ibuf)+fread(ibuf,1,SIZ,stdin),p1==p2)?EOF:*p1++)
// void pc(const char &c)
// {
// if(p3-obuf==SIZ) fwrite(obuf,1,SIZ,stdout),p3=obuf;
// *p3++=c;
// }
int rd()
{
int x=0,f=1;
char ch=gc();
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=gc();
}
while(isdigit(ch)){
x=x*10+ch-'0';
ch=gc();
}
return x*f;
}
void wr(int x,char ch)
{
if(x<0) x=-x,pc('-');
static char st[12];
int top=0;
do{
st[top++]=x%10+'0',x/=10;
}while(x);
while(top) pc(st[--top]);
pc(ch);
}
ll ll_rd()
{
ll x=0;
int f=1;
char ch=gc();
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=gc();
}
while(isdigit(ch)){
x=x*10+ch-'0';
ch=gc();
}
return x*f;
}
void ll_wr(ll x,char ch)
{
if(x<0) x=-x,pc('-');
static char st[22];
int top=0;
do{
st[top++]=x%10+'0',x/=10;
}while(x);
while(top) pc(st[--top]);
pc(ch);
}
}
using namespace IO;
const int N=5005,M=1e4+5,V=N*3,E=N*7+M*2,mod=0;
namespace tem
{
// void add_edge(int u,int v){nxt[++cnt]=head[u],to[cnt]=v,head[u]=cnt;}
int qpow(int a,int b,int p)
{
a%=p;
int res=1;
while(b){
if(b&1) res=1ll*res*a%p;
a=1ll*a*a%p;
b>>=1;
}
return res;
}
int get_inv(int x){return qpow(x,mod-2,mod);}
int lowbit(int x){return x&(-x);}
void add(int &x,const int y){ x=(x+y>=mod?x+y-mod:x+y); }
// int get(int x) {return fa[x]==x?x:fa[x]=get(fa[x])};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
}
using namespace tem;
int n,m,c[N<<1],d[N<<1],e[N<<1];
int s,t;
int cnt=1,head[V],nxt[E<<1],to[E<<1];
ll vol[E<<1];
int now[V],dis[V];
void add_edge(int u,int v,ll d)
{
nxt[++cnt]=head[u];
to[cnt]=v;
vol[cnt]=d;
head[u]=cnt;
}
void add_flow(int u,int v,ll d)
{
add_edge(u,v,d),add_edge(v,u,0);
}
bool bfs()
{
memset(dis,0,sizeof(dis));
queue<int>q;
dis[s]=1;
now[s]=head[s];
q.push(s);
bool flag=false;
while(!q.empty()){
int u=q.front();
q.pop();
for_son(u){
int v=to[e];
if(!dis[v]&&vol[e]){
dis[v]=dis[u]+1;
now[v]=head[v];
q.push(v);
if(v==t) flag=true;
}
}
}
return flag;
}
ll dinic(int u,ll flw)
{
if(u==t) return flw;
ll rst=flw;
for(int e=now[u];e;e=now[u]=nxt[e]){
int v=to[e];
if(dis[v]==dis[u]+1&&vol[e]){
ll k=dinic(v,min(vol[e],rst));
if(!k) dis[v]=0;
vol[e]-=k;
vol[e^1]+=k;
rst-=k;
}
if(!rst) break;
}
return flw-rst;
}
ll mxflow()
{
ll res=0,flw=0;
while(bfs()) while(flw=dinic(s,ll_INF)) res+=flw;
return res;
}
void solve()
{
n=rd(),m=rd();
For(i,1,n*2) c[i]=rd(),d[i]=rd(),e[i]=rd();
s=n*3+1,t=s+1;
For(i,1,n*2){
int j=(i&1)?i+1:i-1;
add_flow(s,i,d[i]),add_flow(i,j,e[i]),add_flow(i,n*2+(i+1)/2,c[i]);
}
For(i,1,n) add_flow(n*2+i,t,c[i*2-1]+c[i*2]);
while(m--){
int A=rd(),B=rd(),a=rd(),b=rd();
add_flow(B,n*2+(A+1)/2,a),add_flow(n*2+(B+1)/2,A,b);
}
ll_wr(mxflow(),'\n');
}
void main()
{
int T=1;
while(T--) solve();
}
/*
*/
}
char bb;
signed main()
{
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
// int st=clock();
ljh::main();
// int ed=clock();
// cerr<<ed-st<<"ms"<<endl;
// cerr<<(&bb-&aa)/1024/1024<<"MB"<<endl;
// fclose(stdin);
// fclose(stdout);
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 21ms
memory: 5484kb
input:
5000 10000 23060775 12 2 255978380 28 517 5 6624 26 151149 45131806 23849036 489 484971 24970 162846 1993316 188305 56311199 2003 211 1 50534913 517527 364913 882765 298 71 26 122914059 13 65459 18150033 20 607 8 380059068 3873712 228 9813 5449 6370 3309369 37410691 8 181 1 62340851 1705 4 107 8 209...
output:
22221781891
result:
wrong answer 1st lines differ - expected: '22929674417', found: '22221781891'