2017.2.9 考试总结

果然考得奇萎……TMD竟然只有60分!!!!!!想揍自己啊啊啊啊啊!!!!!

T1竟然把有依赖背包忘了……

T2不会造树导致公式全错……

T3竟然少打一句话爆零!!!!!!不然AC!!!!!!!想揍自己啊啊啊啊啊啊!!!!!!!

T4炸了……我为什么要打主席树…………

考试一定要对拍!!!

考试一定要对拍!!!

考试一定要对拍!!!

重要的事情说四遍:

考试一定要对拍!!!!!!!

附T3修改AC代码,不许再犯傻逼错误啦!!!!!!!!!!!!

#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 300010
#define r 20010
#define RG register
#define inf 0x3f3f3f3f
#define Inf 99999999999999999LL
using namespace std;
typedef long long LL;
bool vis[N],dfsvis[N];
struct node{
    int x,y;
}sm[N];
struct BiShi{
    int to,next;
}e[N];
int col[N];
int n,m,p,x,y,cnt,sum,ans,siz,w[N],head[N];
inline int Abs(RG const int &a){return a>0?a:-a;}
inline int Max(RG const int &a,RG const int &b){return a>b?a:b;}
inline int Min(RG const int &a,RG const int &b){return a>b?b:a;}
inline bool cmp(RG const node &a,RG const node &b){return a.y<b.y;}
inline int gi(){
    RG int x=0;RG bool flag=0;RG char c=getchar();
    while((c<'0'||c>'9')&&c!='-') c=getchar();
    if(c=='-') c=getchar(),flag=1;
    while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return flag?-x:x;
}
inline void add(RG int from,RG int to){
    e[++cnt].next=head[from];
    e[cnt].to=to;
    head[from]=cnt;
}
inline void dfs(RG int now){
    dfsvis[now]=1;
    col[now]=siz;--sum;
    RG int cnm=head[now];
    while(cnm){
    if(!dfsvis[e[cnm].to]){
        if(!col[e[cnm].to])
            dfs(e[cnm].to);
        else if(vis[col[e[cnm].to]]){
            ans-=w[col[e[cnm].to]];
            vis[col[e[cnm].to]]=0;
        }
    }
    cnm=e[cnm].next;
    }
}
inline void work(){
    n=gi();p=gi();sum=n;ans=0;
    for (RG int i=1;i<=p;++i){
    sm[i].x=gi();
        sm[i].y=gi();
    w[sm[i].x]=sm[i].y;
    }
    m=gi();
    for (RG int i=1;i<=m;++i){
    x=gi();y=gi();
    add(x,y);
    }
    sort(sm+1,sm+p+1,cmp);
    for (RG int i=1;i<=p;++i)
    if(!col[sm[i].x]){
        ans+=sm[i].y;
        siz=sm[i].x;
        vis[sm[i].x]=1;
        memset(dfsvis,0,sizeof(dfsvis));
        dfs(sm[i].x);
        if(!sum) break;
    }
    if(sum){
    printf("NO\n");
    for (RG int i=1;i<=n;++i)
        if(!col[i]){
        printf("%d\n",i);
        break;
        }
    }
    else printf("YES\n%d\n",ans);
}
int main(){
    freopen("pupil.in","r",stdin);
    freopen("pupil.out","w",stdout);
    work();
    fclose(stdin);
    fclose(stdout);
    return 0;
}

是不是只有我今天才知道gdb的用法和欧拉序列离线O(n)求LCA,以及造树模板……

posted @ 2017-02-09 13:21  Super_Nick  阅读(180)  评论(0编辑  收藏  举报