QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#544659#7860. Graph of Maximum Degree 3XfJbUhpyzgaW#WA 0ms19808kbC++143.4kb2024-09-02 19:24:082024-09-02 19:24:08

Judging History

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

  • [2024-09-02 19:24:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:19808kb
  • [2024-09-02 19:24:08]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define N 150010
#define P 998244353
#define GC getchar()
#define PC putchar
using namespace std;
ll re(){
    ll s=0,b=1; char c=GC;
    while(c>'9'||c<'0'){if(c=='-')b=-b; c=GC;}
    while(c<='9'&&c>='0'){s=(s<<1)+(s<<3)+(c^48); c=GC;}
    return s*b;
}
void ks(ll s){
    if(s<0)PC('-'),s=-s;
    if(s>=10)ks(s/10); PC((s%10)|48);
}
int n,m,b[2][N][2],s[2],ds[2][N],vi[N],dl[N],h,t,ytt,yhe[N],x,y,op;
int bh[N],nn,he[N],tt,li[N],cd;
bool V[N];
ll ans;
struct A{int ne,to,co;}yb[N<<3];
struct B{int ne,to;}B[N<<2];
map<int,int>bt[N];
void ad(int x,int y){
    B[++tt].to=y; B[tt].ne=he[x]; he[x]=tt;
    B[++tt].to=x; B[tt].ne=he[y]; he[y]=tt;
}
void dfs(int x,int f,int zz){
    li[++cd]=x; V[x]=1;
    for(int i=he[x]; i; i=B[i].ne){
        int v=B[i].to; if(v==f)continue;
        if(v==zz)op=1; else dfs(v,x,zz);
    }
}
void pd2(int x,int y){
    if(bt[x][y])ans++;
}
void pd3(int x,int y,int z){
    int s=bt[x][y]+bt[y][z]+bt[z][x];
    if(s>=2)ans++;
}
void pd4(int x,int y,int z,int a){
    int s=bt[x][y]+bt[y][z]+bt[x][z]+bt[x][a]+bt[y][a]+bt[z][a];
    //cout<<s<<endl;
    if(s>3){ans++;}
    if(s==3){
        if(bt[x][y]||bt[x][z]||bt[x][a])
         if(bt[y][x]||bt[y][z]||bt[y][a])
          if(bt[z][x]||bt[z][y]||bt[z][a])
           if(bt[a][x]||bt[a][y]||bt[a][z])ans++;
    }
}
int main(){
    //freopen("a.in","r",stdin);
    n=re(),m=re(); ans=n;
    for(int i=1; i<=m; ++i){
        x=re(),y=re(),op=re();
        s[op]++;
        b[op][s[op]][0]=x;
        b[op][s[op]][1]=y;
        ds[op][x]++; ds[op][y]++;
        yb[++ytt].to=y; yb[ytt].ne=yhe[x]; yhe[x]=ytt; yb[ytt].co=op;
        yb[++ytt].to=x; yb[ytt].ne=yhe[y]; yhe[y]=ytt; yb[ytt].co=op;
    } h=1;
    for(int i=1; i<=n; ++i)
     if(ds[0][i]==0||ds[1][i]==0)dl[++t]=i,vi[i]=1;
    while(h<=t){
        x=dl[h++];
        for(int i=yhe[x]; i; i=yb[i].ne){
            int v=yb[i].to,co=yb[i].co; ds[co][v]--;
            if(ds[co][v]==0&&!vi[v]){dl[++t]=v; vi[v]=1;}
        }
    }
    for(int i=1; i<=n; ++i) if(!vi[i])bh[i]=++nn; //cout<<nn<<endl;
    for(int i=1; i<=s[0]; ++i){
        if(bh[b[0][i][0]]&&bh[b[0][i][1]])
         ad(bh[b[0][i][0]],bh[b[0][i][1]]);
    }
    for(int i=1; i<=s[1]; ++i){
        if(bh[b[1][i][0]]&&bh[b[1][i][1]])
         bt[bh[b[1][i][0]]][bh[b[1][i][1]]]=bt[bh[b[1][i][1]]][bh[b[1][i][0]]]=1;
    }
    for(int i=1; i<=nn; ++i){
        if(!V[i]){
            op=cd=0; dfs(i,-1,i);// cout<<cd<<' ';
            if(cd==1)continue;
            if(cd==2){pd2(li[1],li[2]); continue;}
            else for(int j=1; j<=cd; ++j){
                if(j<cd){
                    pd2(li[j],li[j+1]);
                } else{
                    if(op)pd2(li[j],li[1]);
                }
            }
            if(cd==3){pd3(li[1],li[2],li[3]); continue;}
            else{
                for(int j=1; j<=cd; ++j){
                    if(j<cd-1)pd3(li[j],li[j+1],li[j+2]);
                     else if(op)pd3(li[j],li[j%cd+1],li[(j+1)%cd+1]);
                }
            }
            if(cd==4){pd4(li[1],li[2],li[3],li[4]); continue;}
            else{
                for(int j=1; j<=cd; ++j){
                    if(j<cd-2)pd4(li[j],li[j+1],li[j+2],li[j+3]);
                     else if(op)pd4(li[j],li[j%cd+1],li[(j+1)%cd+1],li[(j+2)%cd+1]);
                }
            }
        }
    } ks(ans);
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 19408kb

input:

3 4
1 2 0
1 3 1
2 3 0
2 3 1

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 0ms
memory: 18624kb

input:

4 6
1 2 0
2 3 0
3 4 0
1 4 1
2 4 1
1 3 1

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 19808kb

input:

20 28
9 6 1
9 6 0
3 8 0
8 4 0
3 8 1
3 4 1
2 13 0
13 1 0
19 1 0
2 1 1
2 19 1
13 19 1
14 15 1
14 15 0
7 12 0
12 17 0
20 17 0
7 17 1
7 20 1
12 20 1
16 18 0
18 10 0
5 10 0
16 10 1
16 5 1
18 5 1
4 6 0
9 11 0

output:

29

result:

wrong answer 1st numbers differ - expected: '27', found: '29'