QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#296608 | #7860. Graph of Maximum Degree 3 | Dualqwq# | WA | 2ms | 9676kb | C++20 | 1.7kb | 2024-01-03 10:58:24 | 2024-01-03 10:58:24 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n,m;
vector<int> Gr[N],Gb[N];
bool del[N];
vector<int> V;
int Id[N],vst[N],usd[N];
inline bool Check(vector<int> V) {
// printf("V: \n");
// for(auto i : V) printf("%d ",i);
// printf("\n");
sort(V.begin(),V.end());
V.erase(unique(V.begin(),V.end()),V.end());
int tt = 0;
for(auto i : V) Id[i] = ++tt,vst[i] = 0;
auto dfs0 = [&](const auto &self,int x)->void {
// printf("dfs0:%d\n",x);
vst[x] = true;
for(auto y : Gr[x]) if(!vst[y] && Id[y]) self(self,y);
};
dfs0(dfs0,V[0]);
for(auto i : V) Id[i] = 0;
for(auto i : V) if(!vst[i]) return false;
for(auto i : V) vst[i] = 0,Id[i] = ++tt;
auto dfs1 = [&](const auto &self,int x)->void {
vst[x] = true;
for(auto y : Gb[x]) if(!vst[y] && Id[y]) self(self,y);
};
dfs1(dfs1,V[0]);
for(auto i : V) Id[i] = 0;
for(auto i : V) if(!vst[i]) return false;
// printf("true\n");
return true;
}
void dfsr(int x) {
if(del[x]) return;
usd[x] = true;V.push_back(x);
for(auto y : Gr[x])
if(!usd[y]) dfsr(y);
}
int main() {
cin >> n >> m;
for(int i = 1,u,v,c;i <= m;i++) {
cin >> u >> v >> c;
if(c == 0) Gr[u].push_back(v),Gr[v].push_back(u);
else Gb[u].push_back(v),Gb[v].push_back(u);
}
for(int i = 1;i <= n;i++) if(!Gr[i].size() || !Gb[i].size()) del[i] = true;
int ans = 0;
for(int i = 1;i <= n;i++) if(!del[i] && !usd[i]) {
V.clear();dfsr(i);
int siz = V.size();
for(int i = 0;i < siz;i++) {
vector<int> now;
for(int j = i,d = 0;d < siz - 1 && d <= 6;j = (j + 1) % siz,d++)
now.push_back(V[j]),ans += Check(now);
}
if(siz <= 7) ans += Check(V);
}
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8200kb
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: 8548kb
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: 9676kb
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:
26
result:
wrong answer 1st numbers differ - expected: '27', found: '26'