-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathliarliar.cpp
More file actions
120 lines (99 loc) · 2.3 KB
/
Copy pathliarliar.cpp
File metadata and controls
120 lines (99 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
#define MAXN 5000005
char col[MAXN];
vector<vector<int> > adj;
char buff[105];
char bu2[105];
///////////HASH CODE
// primo cercano al tamaño la tabla
const int NHASH = 29989;
const int MULT = 31;
typedef struct node *nodeptr;
typedef struct node {
char *word;
int id;
nodeptr next;
}node;
nodeptr bin[NHASH];
unsigned int hash(char *p) {
unsigned int h = 0;
for(; *p;p++)
h = MULT * h + *p;
return (h % NHASH);
}
int findid(char *s) {
unsigned int h = hash(s);
nodeptr p;
for(p = bin[h]; p != NULL; p = p->next)
if(strcmp(s,p->word)==0) {
return p->id;
}
return -1;
}
void insertid(char *s,int id) {
unsigned int h = hash(s);
nodeptr p;
p = (nodeptr)malloc(sizeof(node));
p->id = id;
p->word = (char *)malloc(strlen(s)+1);
strcpy(p->word,s );
p->next = bin[h];
bin[h] = p;
}
// Para ejecutar hay que inicilazar
// y luego insertar cada palabra en incword
int main(int argc, char *argv[]){
freopen(argv[1],"r",stdin);
int n;
gets(buff);
sscanf(buff,"%d",&n);
adj.resize(n);
int de;
int c=0;
for(int i=0;i<n;i++){
gets(buff);
sscanf(buff,"%s %d",bu2,&de);
int aa,bb;
if((aa=findid(bu2))==-1){
insertid(bu2,c);
aa=c;
c++;
}
for(int j=0;j<de;j++){
gets(buff);
if((bb=findid(buff))==-1){
insertid(buff,c);
bb=c;
c++;
}
adj[aa].push_back(bb);
adj[bb].push_back(aa);
}
}
//printf("aab\n");
memset(col,-1,sizeof(col));
queue<int> q;
q.push(0);
col[0]=0;
while(!q.empty()){
int x=q.front();q.pop();
for(int i=0;i<adj[x].size();i++)
if(col[adj[x][i]]==-1){
col[adj[x][i]]=(col[x]+1)%2;
q.push(adj[x][i]);
}
}
int a=0,b=0;
for(int i=0;i<n;i++)
if(col[i]==0) a++;
else if(col[i]==1) b++;
cout<<max(a,b)<<" "<<min(a,b)<<endl;
return 0;
}