QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#775665#7860. Graph of Maximum Degree 3123456zmy#RE 2ms6568kbC++142.0kb2024-11-23 16:26:322024-11-23 16:26:33

Judging History

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

  • [2024-11-23 16:26:33]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:6568kb
  • [2024-11-23 16:26:32]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int n,m,x,y,z;
int ans;
int du[100001];
struct yu
{
    int x,y;
    bool operator<(const yu &a)const
    {
        return a.x<x||(a.x==x&&a.y<y);
    }
};
vector<yu>e[100001];
map<yu,int>A;
int main()
{
    scanf("%d %d",&n,&m);
    for (int i=1;i<=m;i++)
    {
        scanf("%d %d %d",&x,&y,&z);
        if (x>y)swap(x,y);
        z++;
        if (A.count((yu){x,y}))A[(yu){x,y}]+=z;
        else A[(yu){x,y}]=z;
    }
    ans=n;
    for (auto [i,j]:A)
    {
        if (j==3)ans++;
        e[i.x].pb((yu){i.y,j}),du[i.y]++;
        e[i.y].pb((yu){i.x,j}),du[i.x]++;
    }
    for (auto [i,j]:A)if (j==3)
    {
        int x=i.x,y=i.y;
        yu o,p;
        for (yu I:e[x])if (I.x!=y)o=(yu){I.x,I.y};
        for (yu I:e[y])if (I.x!=x)p=(yu){I.x,I.y};
        if (o.x==p.x&&o.y!=p.y)ans++;
    }
    int ank=0;
    for (auto [i,j]:A)if (j==3)
    {
        int x=i.x,y=i.y;
        yu o,p;
        for (yu I:e[x])if (I.x!=y)o=(yu){I.x,I.y};
        for (yu I:e[y])if (I.x!=x)p=(yu){I.x,I.y};
        if (o.x!=p.x&&o.y!=p.y)
        {
            if (e[o.x].size()==2&&e[p.x].size()==2)
            {
                yu u,v;
                for (yu I:e[o.x])if (I.x!=x)u=(yu){I.x,I.y};
                for (yu I:e[p.x])if (I.x!=y)v=(yu){I.x,I.y};
                if (u.x==p.x&&v.x==o.x&&u.y==3&&v.y==3)ank++;
            }
        }
    }
    int ano=0;
    for (int i=1;i<=n;i++)if (du[i]==3)
    {
        int l=0,r=0;
        if (e[i][0].y+e[i][1].y+e[i][2].y==4)l++;else if (e[i][0].y+e[i][1].y+e[i][2].y==5)r++;
        vector<yu>b;
        for (yu j:e[i])b.pb(j);
        if (du[b[0].x]!=3||du[b[1].x]!=3||du[b[2].x]!=3)continue;
        for (yu k:b)
        {
            int ii=k.x;
            if (e[ii][0].y+e[ii][1].y+e[ii][2].y==4)l++;else if (e[ii][0].y+e[ii][1].y+e[ii][2].y==5)r++;
        }
        if (l==2&&r==2)ano++;
    }
    printf("%d\n",ans+ank/2+ano/4);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 6372kb

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: 2ms
memory: 6568kb

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
Runtime Error

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:


result: