二试画风清奇

T1普及组水题 BZOJ4500

T2原题 BZOJ4919

前两天加起来1h-

T3毒瘤题 肛了3h+得到0分的好成绩

省选rank44->rank24

T1

#include<cstdio>
#include<algorithm>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
using namespace std;
#define gc getchar()
const int N=2e6+11,inf=(1<<30);
inline int read(){
    char c;while(c=gc,c==' '||c=='\n');int data=0,f=1;
    if(c=='-')f=-1;else data=c-48;
    while(c=gc,c>='0'&&c<='9')data=(data<<1)+(data<<3)+c-48;return data*f;
}
int T,n,m,k,tot,x,y,z;
int nxt[N],las[4011],to[N],w[N],ans[4011];
inline void add(int x,int y,int z){
    nxt[++tot]=las[x],
    las[x]=tot,
    to[tot]=y,
    w[tot]=z;
}
inline void init(){
    rep(i,1,n+m)las[i]=0,ans[i]=-inf;
    tot=0;
}
inline bool bfs(int x){
    for(register int e=las[x];e;e=nxt[e]){
        if(ans[to[e]]==-inf){
            ans[to[e]]=w[e]-ans[x];
            if(!bfs(to[e]))
                return 0;
        }
        else
            if(ans[to[e]]+ans[x]!=w[e])
                return 0;
    }
    return 1;
}
int main(){
    freopen("solo.in","r",stdin);
    freopen("solo.out","w",stdout);
    T=read();
    while(T--){
        n=read(),m=read(),k=read();
        init();
        rep(i,1,k){
            x=read(),y=read()+n,z=read(),
            add(x,y,z),add(y,x,z);
        }
        rep(i,1,n+m)
            if(ans[i]==-inf){
                ans[i]=0;
                if(!bfs(i)){
                    puts("No");
                    goto end;
                }
            }
        puts("Yes");
        end:;
    }
    return 0;
}
T1 code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2021-04-14
  • 2021-10-24
猜你喜欢
  • 2022-12-23
  • 2021-04-06
  • 2021-11-24
  • 2021-04-02
  • 2021-08-30
  • 2022-01-25
  • 2021-05-20
相关资源
相似解决方案