QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#401113 | #7860. Graph of Maximum Degree 3 | ucup-team3282 | WA | 1ms | 5736kb | C++20 | 2.7kb | 2024-04-27 22:05:49 | 2024-04-27 22:05:50 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
vector<pair<int,bool>>link[100050];
int lk[100050];
map<pair<int,int>,int>db;
map<unsigned long long,int>toak;
int vis[100050];
pair<int,int> mp(int x,int y){
if(x>y)return make_pair(y,x);
return make_pair(x,y);
}
bool cmp(unsigned long long a,unsigned long long b){
return a<b;
}
unsigned long long r[4];
unsigned long long mix(long long a,long long b,long long c,long long d){
r[0]=a;r[1]=b;r[2]=c;r[3]=d;
// cout<<r[0]<<"---"<<r[1]<<"---"<<r[2]<<"---"<<r[3]<<endl;
sort(r+0,r+4,cmp);
// cout<<r[0]<<"---"<<r[1]<<endl;
return r[0]+r[1]*100007+r[2]*100007*100007+r[3]*100007*100007*100007;
}
int ans,kkk[10];
void dfs(int p,int fa,int op,int stp){
// cout<<p<<":"<<stp<<endl;
if(vis[p]==0)return;
if(stp==4){
// cout<<"!";
kkk[stp]=p;
unsigned long long r=mix(kkk[1],kkk[2],kkk[3],kkk[4]);
toak[r]++;
if(toak[r]==4)ans++;
// else
return;
}
for(auto x:link[p]){
if(x.first==fa)continue;
if(x.second!=op)continue;
kkk[stp]=p;
dfs(x.first,p,op,stp+1);
}
}
int main(){
int n,m;cin>>n>>m;for(int i=1;i<=m;i++){
int f,t,o;cin>>f>>t>>o;
link[f].push_back(make_pair(t,o));
link[t].push_back(make_pair(f,o));
}
for(int i=1;i<=n;i++){
if(link[i].size()<=1)vis[i]=0;
if(link[i].size()==2){
if(link[i][0].first==link[i][1].first)db[mp(i,link[i][0].first)]=1;
else vis[i]=1;
}
if(link[i].size()==3){
vis[i]=1;
if(link[i][0].second==link[i][1].second&&link[i][1].second==link[i][2].second)vis[i]=0;
else{
if(link[i][0].first==link[i][1].first){
db[mp(i,link[i][0].first)]=1;
lk[i]=link[i][2].first;
}
else if(link[i][0].first==link[i][2].first){
db[mp(i,link[i][0].first)]=1;
lk[i]=link[i][1].first;
}
else if(link[i][1].first==link[i][2].first){
db[mp(i,link[i][1].first)]=1;
lk[i]=link[i][0].first;
}
}
}
}
// cout<<"1:"<<n<<endl;
// cout<<"2:"<<db.size()<<endl;
int cnt=0;
for(auto x:db){
if(lk[x.first.first]==lk[x.first.second]){
cnt++;
}
}
// cout<<"3:"<<cnt<<endl;
for(int i=1;i<=n;i++){
dfs(i,0,0,1);
dfs(i,0,1,1);
}
// cout<<"4:"<<ans<<endl;
cout<<n+db.size()+cnt+ans<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3632kb
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: 5736kb
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: 1ms
memory: 3640kb
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'