QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#635234 | #7860. Graph of Maximum Degree 3 | zhisheng | WA | 252ms | 28624kb | C++20 | 3.0kb | 2024-10-12 19:20:35 | 2024-10-12 19:20:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
mt19937_64 rng(random_device{}());
int random(int l,int r) {
return rng()%(r - l + 1) + l;
}
unordered_map <int,int> mp;
struct DSU {
int n;
std::vector<int> fa, sz;
DSU(int n): n(n) {
fa.resize(n + 1);
sz.resize(n + 1);
for (int i = 0; i <= n; i ++) {
fa[i] = i;
sz[i] = 1;
}
}
int find(int x) {
if (x == fa[x]) return fa[x];
return fa[x] = find(fa[x]);
}
void merge(int x, int y) {
int dx = find(x), dy = find(y);
if (dx != dy) {
sz[dy] += sz[dx];
fa[dx] = dy;
}
}
};
signed main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n,m;
cin >> n >> m;
if(m==0) {
cout << n;
return 0;
}
vector <vector <int>> g1(n + 1);
vector <vector <int>> g2(n + 1);
for(int i=1;i<=m;i++) {
mp[i] = random(1,1e9);
int u , v , w;
cin >> u >> v >> w;
if(w==0) {
g1[u].push_back(v);
g1[v].push_back(u);
}
else {
g2[u].push_back(v);
g2[v].push_back(u);
}
}
// for(int i=1;i<=n;i++) {
// cout << mp[i] << " ";
// }
// cout << "\n";
DSU dsu(n + 1);
vector <int> vis(n + 1);
vector <int> T;
set <int> all;
auto check = [&](int x) {
for(auto i : T) {
if(x== i) return true;
}
return false;
};
auto dfs = [&](auto &dfs,int u)->void {
map <int,int> mpp;
if(T.size() <=4){
for(auto i : T) {
mpp[i] ++ ;
if(mpp[i]>=2) return;
}
set <int> st;
for(auto i : T) {
dsu.fa[i] = i;
}
for(auto i : T) {
for(auto v : g2[i]) {
if(check(v)) {
dsu.merge(i,v);
}
}
}
for(auto i : T) {
st.insert(dsu.fa[i]);
}
// cout << st.size() << "\n";
if(st.size()==1) {
int ans = 0;
for(auto i : T) {
ans ^= mp[i];
}
all.insert(ans);
}
for(auto i : T) {
for(auto v : g2[i]) {
// cout << i << " " << v << "\n";
dsu.fa[i] = i;
dsu.fa[v] = v;
}
}
// cout << "\n";
}
else {
return;
}
for(auto v : g1[u]) {
T.push_back(v);
dfs(dfs,v);
T.pop_back();
}
};
for(int i=1;i<=n;i++) {
T.push_back(i);
dfs(dfs,i);
T.pop_back();
}
cout << all.size() << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
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: 3792kb
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: 0
Accepted
time: 0ms
memory: 3644kb
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:
27
result:
ok 1 number(s): "27"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3652kb
input:
100 150 93 23 0 23 81 0 76 81 0 93 81 1 93 76 1 23 76 1 100 65 0 65 56 0 19 56 0 100 56 1 100 19 1 65 19 1 2 98 0 2 98 1 26 63 0 63 90 0 26 63 1 26 90 1 6 11 0 11 67 0 6 11 1 6 67 1 37 89 0 89 64 0 25 64 0 37 64 1 37 25 1 89 25 1 84 10 0 10 29 0 75 29 0 84 29 1 84 75 1 10 75 1 7 70 1 7 70 0 28 92 0 ...
output:
141
result:
ok 1 number(s): "141"
Test #5:
score: -100
Wrong Answer
time: 252ms
memory: 28624kb
input:
100000 133680 36843 86625 0 86625 63051 0 35524 63051 0 36843 63051 1 36843 35524 1 86625 35524 1 55797 82715 0 55797 82715 1 70147 35104 0 35104 91732 0 70147 35104 1 70147 91732 1 94917 70395 0 70395 68250 0 24100 68250 0 94917 68250 1 94917 24100 1 70395 24100 1 83033 18450 1 83033 18450 0 34462 ...
output:
144596
result:
wrong answer 1st numbers differ - expected: '144604', found: '144596'