QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#540845 | #7860. Graph of Maximum Degree 3 | Repeater | WA | 1ms | 3656kb | C++20 | 3.0kb | 2024-08-31 17:57:24 | 2024-08-31 17:57:26 |
Judging History
answer
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
std::vector<std::vector<std::pair<int, int>>> adj(n);
for (int i = 0; i < m; i++) {
int u, v, w;
std::cin >> u >> v >> w;
u--, v--;
adj[u].emplace_back(v, w);
adj[v].emplace_back(u, w);
}
int ans = n, ans2 = 0, ans3 = 0;
std::vector<int> cnt(n), cnt2(n);
auto check = [&](int x, int y) -> bool {
for (auto [j, c] : adj[x]) cnt2[j]++;
bool ok = cnt2[y] == 2;
for (auto [j, c] : adj[x]) cnt2[j]--;
return ok;
};
for (int i = 0; i < n; i++) {
cnt[0] = 0;
int x = -1, y = -1, z = -1;
int cx = -1, cy = -1, cz = -1;
for (auto [j, c] : adj[i]) {
// std::cerr << j << " ";
cnt[j]++;
if(cnt[j] == 1)
{
if(x == -1) x = j, cx = c;
else if(y == -1) y = j, cy = c;
else if(z == -1) z = j, cz = c;
// std::cerr << x << " " << y << " " << z << " " << j << "\n";
}
if(cnt[j] == 2)
ans3++;
}
// std::cerr << "\n";
if(z == -1)
{
if(cnt[x] == 2)
std::swap(x, y), std::swap(cx, cy);
for(auto [j, c] : adj[x])
if(j == y && c != cx)
ans3++;
for(auto [j, c] : adj[y])
if(check(j, x))
ans2++;
cnt[x] = 0, cnt[y] = 0;
}
else
{
std::array<int, 2> tmp{0, 0};
int a = 0, b = 0;
if(cx == 1) a++;
if(cy == 1) a++;
if(cz == 1) a++;
if(a == 2) tmp[0]++;
else tmp[1]++;
a = 0, b = 0;
for (auto [j, c] : adj[x])
{
cnt[j]++;
if(c == 1) a++;
else b++;
}
if(a == 2 && b == 1) tmp[0]++;
else tmp[1]++;
a = 0, b = 0;
for (auto [j, c] : adj[y])
{
cnt[j]++;
if(c == 1) a++;
else b++;
}
if(a == 2 && b == 1) tmp[0]++;
else tmp[1]++;
a = 0, b = 0;
for (auto [j, c] : adj[z])
{
cnt[j]++;
if(c == 1) a++;
else b++;
}
if(a == 2 && b == 1) tmp[0]++;
else tmp[1]++;
// std::cerr << cnt[x] << " " << cnt[y] << " " << cnt[z] << " " << tmp[0] << " " << tmp[1] << "\n";
if(cnt[x] == cnt[y] && cnt[x] == cnt[z] && cnt[x] == 3 && tmp[0] == 2 && tmp[1] == 2)
ans2++;
cnt[x] = 0, cnt[y] = 0, cnt[z] = 0;
}
}
std::cout << ans + ans3 / 2 + ans2 / 4 << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
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: 3556kb
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: 3656kb
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:
25
result:
wrong answer 1st numbers differ - expected: '27', found: '25'