QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#575849 | #7857. (-1,1)-Sumplete | tosania | WA | 1ms | 7768kb | C++14 | 2.2kb | 2024-09-19 17:01:24 | 2024-09-19 17:01:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 5e5 + 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++;
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){
int po=judge(1,i)+judge(0,i);
if(po==8){
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: 0
Wrong Answer
time: 1ms
memory: 7768kb
input:
3 +-+ -++ +-+ 1 1 1 1 -1 3
output:
3
result:
wrong answer invalid output