Submission #1442933
Source Code Expand
// #includes {{{
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair
#define EXIST(e,s) ((s).find(e)!=(s).end())
#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command
//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;
const int INF=0x3f3f3f3f;
typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;
typedef pair<int,int> pii;
/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}
//{{{ io
FILE *file_in=stdin,*file_out=stdout;
#define fin normal_in
#define fout normal_out
//const char fname[]="";
//FILE *fin=fopen(fname,"r"),*fout=fopen(fname,"w");
#ifdef __MINGW32__
#define LLD "%I64d"
#define LLU "%I64u"
#else
#define LLD "%lld"
#define LLU "%llu"
#endif
struct NORMAL_IN{
bool cnt;
NORMAL_IN():cnt(true){}
operator int() const {return cnt;}
#define endl "\n"
NORMAL_IN& operator>>(int &n){cnt=fscanf(file_in,"%d",&n)!=EOF;return *this;}
NORMAL_IN& operator>>(unsigned int &n){cnt=fscanf(file_in,"%u",&n)!=EOF;return *this;}
NORMAL_IN& operator>>(long long &n){cnt=fscanf(file_in,LLD,&n)!=EOF;return *this;}
NORMAL_IN& operator>>(unsigned long long &n){cnt=fscanf(file_in,LLU,&n)!=EOF;return *this;}
NORMAL_IN& operator>>(double &n){cnt=fscanf(file_in,"%lf",&n)!=EOF;return *this;}
NORMAL_IN& operator>>(long double &n){cnt=fscanf(file_in,"%Lf",&n)!=EOF;return *this;}
NORMAL_IN& operator>>(char *c){cnt=fscanf(file_in,"%s",c)!=EOF;return *this;}
NORMAL_IN& operator>>(string &s){
s.clear();
for(bool r=false;;){
const char c=getchar();
if(c==EOF){ cnt=false; break;}
const int t=isspace(c);
if(!r and !t)r=true;
if(r){
if(!t)s.push_back(c);
else break;
}
}
return *this;
}
template<class T>
NORMAL_IN& operator>>(vector<T> &v){
int n;fscanf(file_in,"%d",&n);
REP(i,n){
T t;*this>>t;
v.push_back(t);
}
}
} normal_in;
struct NORMAL_OUT{
NORMAL_OUT& operator<<(const int &n){fprintf(file_out,"%d",n);return *this;}
NORMAL_OUT& operator<<(const unsigned int &n){fprintf(file_out,"%u",n);return *this;}
NORMAL_OUT& operator<<(const long long &n){fprintf(file_out,LLD,n);return *this;}
NORMAL_OUT& operator<<(const unsigned long long &n){fprintf(file_out,LLU,n);return *this;}
NORMAL_OUT& operator<<(const double &n){fprintf(file_out,"%lf",n);return *this;}
NORMAL_OUT& operator<<(const long double &n){fprintf(file_out,"%Lf",n);return *this;}
NORMAL_OUT& operator<<(const char c[]){fprintf(file_out,"%s",c);return *this;}
NORMAL_OUT& operator<<(const string &s){fprintf(file_out,"%s",s.c_str());return *this;}
} normal_out;
//}}}
//{{{ Graph
typedef int Weight;
struct Edge {
int src, dst, rev;
Weight weight;
Edge(int src, int dst, Weight weight=1,int rev=-1) :
src(src), dst(dst), weight(weight), rev(rev) { }
};
bool operator < (const Edge &e, const Edge &f) {
return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
//typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
struct Graph:vector<Edges>{
Graph(){}
Graph(const int &n){this->assign(n,Edges());}
//add bi-directional edge
void addBiEdge(int from ,int to, Weight w=1){
while(this->size()<max(from,to)+1)this->push_back(Edges());
this->at(from).push_back(Edge(from,to,w,this->at(to).size()));
this->at(to).push_back(Edge(to,from,w,this->at(from).size()-1));
}
//add directional edge
void addEdge(int from ,int to, Weight w=1){
while(this->size()<from+1)this->push_back(Edges());
this->at(from).push_back(Edge(from,to,w));
}
};
#ifdef DEBUG
#include"graph/graphviz.h"
#endif
//}}}
int N;
Graph G;
int dfs(int u=0,int p=-1){
int s = 0;
for(const auto &e:G[u]){
if(p==e.dst)continue;
s^=(dfs(e.dst,u)+1);
}
return s;
}
int main(){
fin>>N;
G.assign(N,{});
REP(i,N-1){
int x,y;
fin>>x>>y;
x--;y--;
G.addBiEdge(x,y);
}
auto u(dfs());
if(u==0){
fout<<"Bob"<<endl;
}else{
fout<<"Alice"<<endl;
}
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Game on Tree |
User |
chaemon |
Language |
C++14 (GCC 5.4.1) |
Score |
1100 |
Code Size |
4838 Byte |
Status |
AC |
Exec Time |
48 ms |
Memory |
12544 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
1100 / 1100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample1.txt, sample2.txt, sample3.txt, sample4.txt |
All |
sample1.txt, sample2.txt, sample3.txt, sample4.txt, a1.txt, a10.txt, a11.txt, a12.txt, a13.txt, a14.txt, a15.txt, a16.txt, a17.txt, a18.txt, a19.txt, a2.txt, a20.txt, a21.txt, a22.txt, a23.txt, a24.txt, a25.txt, a26.txt, a27.txt, a28.txt, a29.txt, a3.txt, a30.txt, a4.txt, a5.txt, a6.txt, a7.txt, a8.txt, a9.txt, b1.txt, b2.txt, b3.txt, b4.txt, b5.txt, sample1.txt, sample2.txt, sample3.txt, sample4.txt |
Case Name |
Status |
Exec Time |
Memory |
a1.txt |
AC |
1 ms |
256 KB |
a10.txt |
AC |
5 ms |
1152 KB |
a11.txt |
AC |
5 ms |
1152 KB |
a12.txt |
AC |
5 ms |
1152 KB |
a13.txt |
AC |
41 ms |
7680 KB |
a14.txt |
AC |
42 ms |
7680 KB |
a15.txt |
AC |
33 ms |
6272 KB |
a16.txt |
AC |
42 ms |
7936 KB |
a17.txt |
AC |
42 ms |
7936 KB |
a18.txt |
AC |
40 ms |
7936 KB |
a19.txt |
AC |
41 ms |
8704 KB |
a2.txt |
AC |
2 ms |
384 KB |
a20.txt |
AC |
45 ms |
9088 KB |
a21.txt |
AC |
35 ms |
7424 KB |
a22.txt |
AC |
41 ms |
7680 KB |
a23.txt |
AC |
41 ms |
7680 KB |
a24.txt |
AC |
33 ms |
6272 KB |
a25.txt |
AC |
42 ms |
7936 KB |
a26.txt |
AC |
43 ms |
7936 KB |
a27.txt |
AC |
46 ms |
7936 KB |
a28.txt |
AC |
41 ms |
8704 KB |
a29.txt |
AC |
44 ms |
9088 KB |
a3.txt |
AC |
3 ms |
640 KB |
a30.txt |
AC |
35 ms |
7424 KB |
a4.txt |
AC |
5 ms |
1024 KB |
a5.txt |
AC |
5 ms |
1024 KB |
a6.txt |
AC |
5 ms |
1024 KB |
a7.txt |
AC |
5 ms |
1024 KB |
a8.txt |
AC |
5 ms |
1024 KB |
a9.txt |
AC |
5 ms |
1024 KB |
b1.txt |
AC |
45 ms |
12544 KB |
b2.txt |
AC |
44 ms |
10240 KB |
b3.txt |
AC |
48 ms |
12544 KB |
b4.txt |
AC |
46 ms |
10112 KB |
b5.txt |
AC |
46 ms |
10112 KB |
sample1.txt |
AC |
1 ms |
256 KB |
sample2.txt |
AC |
1 ms |
256 KB |
sample3.txt |
AC |
1 ms |
256 KB |
sample4.txt |
AC |
1 ms |
256 KB |