QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#549822#7860. Graph of Maximum Degree 3cyc_43346WA 1ms8492kbC++141.9kb2024-09-06 21:49:142024-09-06 21:49:14

Judging History

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

  • [2024-09-06 21:49:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:8492kb
  • [2024-09-06 21:49:14]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<vector>
#include<set>
#include<utility>
#define RI register int
#define CI const int&
#define fi first
#define se second
using namespace std;
typedef pair <int,int> pi;
const int N=100005;
int n,m,x,y,z,ans,vis[N],fa[N]; vector <int> v[N]; set <pi> edges[2]; vector <pi> all[N];
inline int getfa(CI x)
{
    return fa[x]!=x?fa[x]=getfa(fa[x]):x;
}
inline int check(vector <int> pnt)
{
    RI i,j; for (auto x:pnt) fa[x]=x;
    for (i=0;i<pnt.size();++i)
    for (j=1;j<pnt.size();++j)
    if (edges[0].count(pi(pnt[i],pnt[j]))) fa[getfa(pnt[i])]=getfa(pnt[j]);
    for (i=1;i<pnt.size();++i)
    if (getfa(pnt[i])!=getfa(pnt[0])) return 0;
    for (auto x:pnt) fa[x]=x;
    for (i=0;i<pnt.size();++i)
    for (j=1;j<pnt.size();++j)
    if (edges[1].count(pi(pnt[i],pnt[j]))) fa[getfa(pnt[i])]=getfa(pnt[j]);
    for (i=1;i<pnt.size();++i)
    if (getfa(pnt[i])!=getfa(pnt[0])) return 0;
    return 1;
}
inline void DFS(CI now,vector <int>& pnt)
{
    vis[now]=1; pnt.push_back(now);
    for (auto [to,c]:all[now]) if (!vis[to]) DFS(to,pnt);
}
int main()
{
    RI i; for (scanf("%d%d",&n,&m),i=1;i<=m;++i)
    {
        scanf("%d%d%d",&x,&y,&z);
        all[x].push_back(pi(y,z)); all[y].push_back(pi(x,z));
        edges[z].insert(pi(x,y)); edges[z].insert(pi(y,x));
        if (z==0) v[x].push_back(y),v[y].push_back(x);
    }
    for (i=1;i<=n;++i) for (auto j:v[i])
    if (edges[1].count(pi(i,j)))
    {
        ++ans; pi it1=pi(-1,-1),it2=pi(-1,-1);
        for (auto [to,c]:all[i]) if (to!=j) it1=pi(to,c);
        for (auto [to,c]:all[j]) if (to!=i) it2=pi(to,c);
        if (it1.fi==-1||it2.fi==-1) continue;
        if (it1.fi==it2.fi&&it1.se!=it2.se) ++ans;
    }
    for (ans/=2,ans+=n,cout<<ans<<endl,i=1;i<=n;++i) if (!vis[i])
    {
        vector <int> pnt; DFS(i,pnt);
        if (pnt.size()==4) ans+=check(pnt);
    }
    return printf("%d",ans),0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 8492kb

input:

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

output:

5
5

result:

wrong answer Output contains longer sequence [length = 2], but answer contains 1 elements