QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#294496 | #7860. Graph of Maximum Degree 3 | brakzero | WA | 2ms | 8796kb | C++14 | 1.5kb | 2023-12-30 14:11:45 | 2023-12-30 14:11:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
vector<int> road[100001],road2[100001];
int n,m,res,tot,gone[100001],cnt=0,sta[100001],top,heart;
int bac[100001],fa[100001];
void dfs(int x)
{
if(gone[x]) return ;
gone[x]=tot;
sta[++top]=x;
++cnt;
for(int i=0;i<road[x].size();++i)
{
dfs(road[x][i]);
}
}
int link(int x,int y)
{
for(int i=0;i<road2[x].size();++i)
{
int v=road2[x][i];
if(v==y) return 1;
}
return 0;
}
int find_(int x)
{
return fa[x]=fa[x]==x?x:find_(fa[x]);
}
void merge(int x,int y)
{
x=find_(x);
y=find_(y);
if(x!=y) fa[x]=y;
}
int main()
{
scanf("%d %d",&n,&m);
for(int i=1,u,v,opt;i<=m;++i)
{
scanf("%d %d %d",&u,&v,&opt);
if(opt) {road[u].push_back(v);road[v].push_back(u);}
else {road2[u].push_back(v);road2[v].push_back(u);}
}
for(int i=1;i<=n;++i)
{
++res;
if(!road[i].size()||!road2[i].size())
{
road[i].clear();
road2[i].clear();
}
}
for(int i=1;i<=n;++i)
{
for(int j=0;j<road[i].size();++j)
{
if(i<road[i][j]&&link(i,road[i][j]))
{
++res;
}
}
}
for(int i=1;i<=n;++i)
{
if(!gone[i])
{
++tot;
cnt=0;
top=0;
dfs(i);
if(cnt<=4)
{
for(int i=1;i<=top;++i) fa[sta[i]]=sta[i];
for(int i=1;i<=top;++i)
{
int x=sta[i];
for(int j=0;j<road2[x].size();++j)
{
merge(x,road2[x][j]);
}
}
int y=1,now=find_(sta[1]);
for(int i=2;i<=top;++i)
{
if(find_(sta[i])!=now) y=0;
}
res+=y;
}
}
}
cout<<res;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 8464kb
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: 1ms
memory: 8476kb
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: 2ms
memory: 8796kb
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:
30
result:
wrong answer 1st numbers differ - expected: '27', found: '30'