QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#575904 | #7860. Graph of Maximum Degree 3 | tosania | WA | 18ms | 18940kb | C++14 | 2.5kb | 2024-09-19 17:15:53 | 2024-09-19 17:15:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 5;
int T;
inline int read() {
int al = 0, fh = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
al = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0') {
al = al * 10 + ch - '0';
ch = getchar();
}
return al * fh;
}
int num_edge, head[N], n, m, al[N], num, al_[2][N], vis[N], anss;
struct Edge {
int to, next, type;
} edge[N * 2];
void add_edge(int from, int to, int type) {
edge[++num_edge].to = to;
edge[num_edge].next = head[from];
edge[num_edge].type = type;
head[from] = num_edge;
}
void dfs(int u) {
num++;
al[u] = 1;
for (int i = head[u]; i; i = edge[i].next) {
if (al[edge[i].to] == 0)
dfs(edge[i].to);
}
}
void test(int u) {
vis[u] = 1;
int o[4], cnt = 0;
for (int i = head[u]; i; i = edge[i].next) {
o[++cnt] = edge[i].to;
}
sort(o + 1, o + cnt + 1);
if (cnt == 1)
return ;
if (o[2] - o[1] == 0) {
vis[o[2]] = 1;
anss++;
if (cnt == 3) {
int ok = 0;
for (int i = head[o[3]]; i; i = edge[i].next) {
if (edge[i].type == 1 && (edge[i].to == u || edge[i].to == o[2])) {
ok = 1;
}
}
if (ok == 0)
return ;
ok = 0;
for (int i = head[o[3]]; i; i = edge[i].next) {
if (edge[i].type == 0 && (edge[i].to == u || edge[i].to == o[2])) {
ok = 1;
}
}
anss += ok;
}
}
if (cnt == 3 && o[3] - o[2] == 0) {
vis[o[2]] = 1;
anss++;
int ok = 0;
for (int i = head[o[1]]; i; i = edge[i].next) {
if (edge[i].type == 1 && (edge[i].to == u || edge[i].to == o[2])) {
ok = 1;
}
}
if (ok == 0)
return ;
ok = 0;
for (int i = head[o[1]]; i; i = edge[i].next) {
if (edge[i].type == 0 && (edge[i].to == u || edge[i].to == o[2])) {
ok = 1;
}
}
anss += ok;
}
}
int judge(int ty, int u) {
int ans = 0;
al_[ty][u] = 1;
for (int i = head[u]; i; i = edge[i].next) {
if (edge[i].type == ty && al_[ty][edge[i].to] == 0) {
ans += judge(ty, edge[i].to);
}
}
return ans + 1;
}
signed main() {
n = read();
m = read();
for (int i = 1; i <= m; i++) {
int u = read(), v = read(), t = read();
add_edge(u, v, t);
add_edge(v, u, t);
}
anss = n;
for (int i = 1; i <= n; i++) {
if (al[i] == 0) {
num = 0;
dfs(i);
if (num == 4) {
if (judge(1, i) == 4&&judge(0, i)==4) {
anss++;
}
}
}
}
//cout<<anss<<" ";
for (int i = 1; i <= n; i++) {
if (!vis[i])
test(i);
}
cout << anss;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5592kb
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: 7668kb
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: 1ms
memory: 9684kb
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: 0ms
memory: 11792kb
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: 0
Accepted
time: 7ms
memory: 17500kb
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:
144604
result:
ok 1 number(s): "144604"
Test #6:
score: -100
Wrong Answer
time: 18ms
memory: 18940kb
input:
100000 133388 86620 74346 0 74346 19047 0 54911 19047 0 86620 19047 1 86620 54911 1 74346 54911 1 23715 93094 0 93094 91208 0 63189 91208 0 23715 91208 1 23715 63189 1 93094 63189 1 99337 41426 1 99337 41426 0 83742 45546 0 45546 73862 0 83742 45546 1 83742 73862 1 85256 2812 0 2812 59368 0 85918 59...
output:
144349
result:
wrong answer 1st numbers differ - expected: '144348', found: '144349'