QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#296483 | #7860. Graph of Maximum Degree 3 | ucup-team1766 | WA | 0ms | 3604kb | C++14 | 2.1kb | 2024-01-03 05:22:33 | 2024-01-03 05:22:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<pair<int, int>> graph[n];
for (int i = 0; i < m; i++) {
int u, v, c;
cin >> u >> v >> c;
graph[--u].push_back({--v, c});
graph[v].push_back({u, c});
}
map<int, int> match;
for (int i = 0; i < n; i++) {
set<int> seen;
for (pair<int, int> e : graph[i]) {
if (seen.count(e.first) && i < e.first) {
match[i] = e.first;
}
seen.insert(e.first);
}
}
long long res = n + match.size();
long long fours1 = 0;
for (pair<int, int> p : match) {
int n1 = -1;
int c1 = -1;
for (pair<int, int> e : graph[p.first]) {
if (e.first != p.second) {
n1 = e.first;
c1 = e.second;
}
}
int n2 = -1;
int c2 = -1;
for (pair<int, int> e : graph[p.second]) {
if (e.first != p.first) {
n2 = e.first;
c2 = e.second;
}
}
if (n1 != -1 && n2 != -1) {
if (n1 == n2 && c1 != c2 && graph[n1].size() == 2) {
res++;
} else if (n1 != n2 && match[min(n1, n2)] == max(n1, n2) && c1 != c2) {
fours1++;
}
}
}
long long fours2 = 0;
for (int u = 0; u < n; u++) {
set<int> comp;
comp.insert(u);
for (pair<int, int> e : graph[u]) {
comp.insert(e.first);
}
if (comp.size() == 4) {
int cnt[] = {0, 0};
for (int v : comp) {
for (pair<int, int> e : graph[v]) {
if (comp.count(e.first)) {
cnt[e.second]++;
}
}
}
if (cnt[0] == 6 && cnt[1] == 6) {
fours2++;
}
}
}
cout << (res + fours1 / 2 + fours2 / 4) % MOD << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
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: 3600kb
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: 3604kb
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'