QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#354211 | #7860. Graph of Maximum Degree 3 | ucup-team1198# | WA | 1ms | 3560kb | C++20 | 2.9kb | 2024-03-14 23:40:31 | 2024-03-14 23:40:32 |
Judging History
answer
#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;
const int MAXN = 100100;
vector<int> G[2][MAXN];
int timer[MAXN];
int par[MAXN];
int ttime = 0;
int get(int v) {
if (v == par[v])
return v;
return par[v] = get(par[v]);
}
bool merge(int v, int u) {
v = get(v);
u = get(u);
if (v == u)
return false;
par[v] = u;
return true;
}
bool check_set(const vector<int>& vs) {
++ttime;
for (int u : vs) {
timer[u] = ttime;
}
for (int c = 0; c < 2; ++c) {
for (int u : vs)
par[u] = u;
int comps = vs.size();
for (int u : vs) {
for (int v : G[c][u]) {
if (timer[v] == ttime)
comps -= merge(v, u);
}
}
if (comps != 1)
return false;
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int a, b, c;
cin >> a >> b >> c;
--a;
--b;
G[c][a].emplace_back(b);
G[c][b].emplace_back(a);
}
int ans = n;
vector<bool> is_good(n);
for (int i = 0; i < n; ++i)
is_good[i] = !G[0][i].empty() && !G[1][i].empty();
vector<bool> was(n);
vector<int> curr;
for (int i = 0; i < n; ++i) {
if (!is_good[i])
continue;
if (was[i])
continue;
vector<int> path;
int cur = i;
while (true) {
path.emplace_back(cur);
was[cur] = true;
int to_next = -1;
for (int nxt : G[0][cur]) {
if (is_good[nxt] && !was[nxt]) {
to_next = nxt;
break;
}
}
if (to_next == -1)
break;
cur = to_next;
}
bool is_cycle = false;
for (int tmp : G[0][path.front()]) {
if (tmp == path.back())
is_cycle = true;
}
int look_mx = min(4, int(path.size() - 1));
if (path.size() <= 4) {
ans += check_set(path);
}
for (int j = 0; j < path.size(); ++j) {
for (int l = 2; l <= look_mx; ++l) {
if (j < l && !is_cycle)
continue;
for (int k = 0; k < l; ++k)
curr.emplace_back(path[(j - k + path.size()) % path.size()]);
ans += check_set(curr);
curr.clear();
}
}
}
cout << ans << '\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: 1ms
memory: 3508kb
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: 3560kb
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'