QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#102763 | #5522. F*** 3-Colorable Graphs | qawszx# | RE | 1ms | 13208kb | C++14 | 1.5kb | 2023-05-03 17:27:52 | 2023-05-03 17:27:56 |
Judging History
answer
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#define ll long long
#define qwq 500007
inline int read(){
char c=getchar();
int x=0;int flag=0;
for(;c<'0'||c>'9';c=getchar())flag|=(c=='-');
for(;c<='9'&&c>='0';c=getchar())x=(x<<1)+(x<<3)+c-'0';
if(flag)return -x;
return x;
}
struct Edge{
int a,b;
}e[qwq];
int n,m;
int cnte=-1;
int first[qwq],next_[qwq<<1],to[qwq<<1];
inline void add(int a,int b){
++cnte;
next_[cnte]=first[a];
first[a]=cnte;
to[cnte]=b;
return ;
}
inline void add_e(int a,int b){
add(a,b);
add(b,a);
return ;
}
int Flag;
int deg[qwq];
std::vector<int>edge[10007];
int tag[qwq];
int main(){
cnte=-1;
memset(first,-1,sizeof(first));
n=read();m=read();
for(int i=1;i<=m;++i){
e[i].a=read(),e[i].b=read();
add_e(e[i].a,e[i].b);
++deg[e[i].a];++deg[e[i].b];
}
for(int i=1;i<=m;++i){
if(deg[e[i].a]<deg[e[i].b]||(deg[e[i].a]==deg[e[i].b]&&e[i].a<e[i].b)){
edge[e[i].a].push_back(e[i].b);
// printf("add:%d->%d\n",e[i].a,e[i].b);
}
}
for(int i=1;i<=n+n;++i){
for(int j=first[i];j!=-1;j=next_[j]){
int v=to[j];
for(int k=0;k<edge[v].size();++k){
int w=edge[v][k];
if(w==i)continue;
if(tag[w]){
Flag=1;
goto here;
}
tag[w]=1;
}
}
for(int j=first[i];j!=-1;j=next_[j]){
int v=to[j];
for(int k=0;k<edge[v].size();++k){
int w=edge[v][k];
if(w==i)continue;
tag[w]=0;
}
}
}
here:;
if(Flag){
printf("%d\n",2);
}
else {
printf("%d\n",3);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 13204kb
input:
2 4 1 3 1 4 2 3 2 4
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 1ms
memory: 13208kb
input:
3 5 1 4 2 4 2 5 3 5 3 6
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: -100
Runtime Error
input:
10000 20000 4570 11730 8803 16440 4257 15381 4455 17636 5256 13543 2172 18421 7735 17847 8537 16010 6175 12263 1079 13410 335 15901 3272 16233 7435 11454 4469 13374 1564 13416 1264 13446 7484 14510 8193 12267 628 15585 1388 11398 5444 19958 2059 18140 8947 13188 6214 17707 7940 12253 6726 11508 1839...