QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#545114#7860. Graph of Maximum Degree 3_gch_WA 4ms20524kbC++143.3kb2024-09-02 22:50:322024-09-02 22:50:33

Judging History

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

  • [2024-09-02 22:50:33]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:20524kb
  • [2024-09-02 22:50:32]
  • 提交

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,zds[N];
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;
    zds[x]++; zds[y]++;
}
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||v==zz)continue;
        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){
    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]==0&&zds[i]==1){
            cd=0; dfs(i,-1,i);// cout<<cd<<' ';
            if(cd==1)continue;
            if(cd==2){pd2(li[1],li[2]); continue;}
            for(int j=1; j<cd; ++j) pd2(li[j],li[j+1]);
            if(cd==3){pd3(li[1],li[2],li[3]); continue;}
            for(int j=1; j<cd-1; ++j)pd3(li[j],li[j+1],li[j+2]);
            if(cd==4){pd4(li[1],li[2],li[3],li[4]); continue;}
            for(int j=1; j<cd-2; ++j)pd4(li[j],li[j+1],li[j+2],li[j+3]);
        }
    }
	for(int i=1; i<=nn; ++i){
        if(V[i]==0){
            cd=0; dfs(i,-1,i);// cout<<cd<<' ';
            if(cd==1)continue;
            if(cd==2){pd2(li[1],li[2]); continue;}
            for(int j=1; j<=cd; ++j) pd2(li[j],li[j%cd+1]);
            if(cd==3){pd3(li[1],li[2],li[3]); continue;}
            for(int j=1; j<=cd; ++j) 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;}
            for(int j=1; j<=cd; ++j) pd4(li[j],li[j%cd+1],li[(j+1)%cd+1],li[(j+2)%cd+1]);
        }
    }
	ks(ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 17372kb

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: 20400kb

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: 0
Accepted
time: 0ms
memory: 17000kb

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:

27

result:

ok 1 number(s): "27"

Test #4:

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

input:

100 150
93 23 0
23 81 0
76 81 0
93 81 1
93 76 1
23 76 1
100 65 0
65 56 0
19 56 0
100 56 1
100 19 1
65 19 1
2 98 0
2 98 1
26 63 0
63 90 0
26 63 1
26 90 1
6 11 0
11 67 0
6 11 1
6 67 1
37 89 0
89 64 0
25 64 0
37 64 1
37 25 1
89 25 1
84 10 0
10 29 0
75 29 0
84 29 1
84 75 1
10 75 1
7 70 1
7 70 0
28 92 0
...

output:

149

result:

wrong answer 1st numbers differ - expected: '141', found: '149'