记录编号 |
392922 |
评测结果 |
TTTTTTTTTT |
题目名称 |
[HZOI 2016]MC之旅:逃离基友 |
最终得分 |
0 |
用户昵称 |
AntiLeaf |
是否通过 |
未通过 |
代码语言 |
C++ |
运行时间 |
5.000 s |
提交时间 |
2017-04-09 15:23:31 |
内存使用 |
1.52 MiB |
显示代码纯文本
#include <cstdio>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int INF=0x7FFFFFFF;
const int MAXV=10010;
const int MAXE=100010;
struct Edge{
int from;
int to;
Edge* next;
};
Edge E[MAXE];
Edge* head[MAXV];
Edge* top=E;
int v;
int m;
int deep;
bool mark[MAXV];
int marked[MAXV];
int topm;
bool Initialize();
bool Solve();
bool DFS(int);
void Insert(int,int);
int False(int);
void FastRead(int&);
int Main(){
while(Initialize()){
// puts("Initialized");
if(Solve()){
for(int i=1;i<=(v<<1);i++){
if(mark[i])
printf("%d ",i);
}
}
else{
printf("die");
}
putchar('\n');
}
return 0;
}
bool Solve(){
topm=0;
if(!DFS(0)){
return false;
}
for(int i=1;i<=(v<<1);i+=2){
if(!mark[i]&&!mark[False(i)]){
topm=0;
if(!DFS(i)){
while(topm>0)mark[marked[--topm]]=false;
if(!DFS(False(i))){
return false;
}
}
}
}
return true;
}
bool DFS(int root){
if(mark[False(root)]){
return false;
}
if(mark[root]){
return true;
}
mark[root]=true;
marked[topm++]=root;
for(Edge* i=head[root];i!=NULL;i=i->next){
if(!DFS(i->to)){
return false;
}
}
return true;
}
inline void Insert(int from,int to){
if(from==to)
return;
top->from=from;
top->to=to;
top->next=head[from];
head[from]=top;
top++;
}
bool Initialize(){
#ifndef ASC_LOCAL
freopen("T3_.in","r",stdin);
freopen("T3_.out","w",stdout);
#endif
if(scanf("%d%d",&v,&m)!=2)
return false;
int tmp;
int a,b;
memset(marked,0,sizeof(marked));
memset(mark,0,sizeof(mark));
memset(head,0,sizeof(head));
top=E;
topm=0;
for(int i=0;i<m;i++){
scanf("%d",&tmp);
switch(tmp){
case 1:// a=true;
FastRead(a);
Insert(0,a);
break;
case 2:// a=false;
FastRead(a);
Insert(0,False(a));
break;
case 3:// a&&b=true;
FastRead(a);
FastRead(b);
Insert(a,b);
Insert(b,a);
break;
case 4:// a&&(!b)=true;
FastRead(a);
FastRead(b);
Insert(a,False(b));
Insert(False(b),a);
break;
case 5:// a||b=true;
FastRead(a);
FastRead(b);
Insert(False(b),a);
Insert(False(a),b);
break;
case 6:// a||(!b)=true;
FastRead(a);
FastRead(b);
Insert(False(a),False(b));
Insert(b,a);
break;
case 7:// !(i&&j)=true;
FastRead(a);
FastRead(b);
Insert(a,False(b));
Insert(b,False(a));
break;
case 8:// !(i||j)=true;
FastRead(a);
FastRead(b);
Insert(False(a),False(b));
Insert(False(b),False(a));
break;
case 9:// i^j=true;
FastRead(a);
FastRead(b);
Insert(False(a),b);
Insert(b,False(a));
Insert(a,False(b));
Insert(False(b),a);
break;
case 10:// !(i^j)=true;
FastRead(a);
FastRead(b);
Insert(a,b);
Insert(b,a);
Insert(False(a),False(b));
Insert(False(b),False(a));
break;
case 11:// i^(!j)=true;
FastRead(a);
FastRead(b);
Insert(a,b);
Insert(b,a);
Insert(False(a),False(b));
Insert(False(b),False(a));
break;
case 12:// (!i)||(!j)=true;
FastRead(a);
FastRead(b);
Insert(a,False(b));
Insert(b,False(a));
break;
}
}
return true;
}
inline int False(int x){
return (x&1)==0?x-1:x+1;
}
void FastRead(int& target){
/* target=0;
bool inv=false;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
inv=true;
if(ch==EOF)
return;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
target=target*10+ch-'0';
ch=getchar();
}
if(inv)
target=-target; */
scanf("%d",&target);
}
int WORKING=Main();
int main(){;}
/*
4 6
3 1 4
5 5 6
5 5 7
2 3
9 1 2
9 5 4
*/