QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#293194 | #7860. Graph of Maximum Degree 3 | ucup-team139 | WA | 1ms | 3556kb | C++23 | 1.9kb | 2023-12-28 23:09:17 | 2023-12-28 23:09:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
void solve(int t){
int n,m;
cin>>n>>m;
vector red(n,vector<int>()),blue(n,vector<int>());
map<pair<int,int>,int> cont;
for(int i=0;i<m;i++){
int u,v,c;
cin>>u>>v>>c;
u--;
v--;
cont[{min(u,v),max(u,v)}]++;
(c == 0 ? red : blue)[u].push_back(v);
(c == 0 ? red : blue)[v].push_back(u);
}
vector vis(n,false);
int ans = n;
for(auto [i,j] : cont)if(j==2)ans++;
for(int i=0;i<n;i++){
if(red[i].size()==3){
vis[i]=true;
}
}
vector<int> v;
auto dfs = [&](auto &dfs,int nodo){
if(vis[nodo])return;
v.push_back(nodo);
vis[nodo]=true;
for(auto i : red[nodo])dfs(dfs,i);
};
vector ok(n,false);
for(int i=0;i<n;i++){
if(vis[i]==false){
v.clear();
dfs(dfs,i);
for(int i=0;i<(int)v.size();i++){
for(int j=i+2;j<min((int)v.size(),i+4);j++){
int cc=0;
for(int k=i;k<=j;k++){
ok[v[k]]=true;
}
for(int k=i;k<=j;k++){
for(auto l : blue[v[k]]){
if(ok[l])cc++;
}
}
for(int k=i;k<=j;k++){
ok[v[k]]=false;
}
//cout<<i<<" "<<j<<" "<<cc<<" ecco\n";
assert(cc%2==0);
if(cc/2==j-i)ans++;
}
}
}
}
//assert(ans<mod);
cout<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)solve(i);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3556kb
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: 3444kb
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: 3480kb
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:
28
result:
wrong answer 1st numbers differ - expected: '27', found: '28'