Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <vector>
- #include <list>
- using namespace std;
- class Graph
- {
- int V;
- list<int> *adj;
- list<int> *lead;
- public:
- Graph(int V);
- void add_edge(int v, int w);
- bool others_leading(int u, int v, int y);
- bool is_reachable(int s, int d);
- };
- Graph::Graph(int V)
- {
- this->V = V;
- adj = new list<int>[V];
- lead = new list<int>[V];
- }
- void Graph::add_edge(int v, int w)
- {
- adj[v].push_back(w);
- lead[w].push_back(v);
- }
- bool Graph::others_leading(int u, int v, int y)
- {
- list<int>::iterator i;
- for (i = lead[v].begin(); i != lead[v].end(); ++i) if (*i != u) return true;
- for (i = lead[y].begin(); i != lead[y].end(); ++i) if (*i != u && *i != v) return true;
- return false;
- }
- bool Graph::is_reachable(int s, int d)
- {
- bool *visited = new bool[V];
- for (int i = 0; i < V; i++)
- visited[i] = false;
- list<int> queue;
- visited[s] = true;
- queue.push_back(s);
- list<int>::iterator i;
- while (!queue.empty())
- {
- s = queue.front();
- queue.pop_front();
- for (i = adj[s].begin(); i != adj[s].end(); ++i)
- {
- if (*i == d)
- return true;
- if (!visited[*i])
- {
- visited[*i] = true;
- queue.push_back(*i);
- }
- }
- }
- return false;
- }
- int main() {
- int n, m, u, v, y;
- scanf("%d %d", &n, &m);
- Graph g(1000000);
- for (int i = 0; i < m; i++) {
- scanf("%d %d", &u, &v);
- g.add_edge(u, v);
- }
- for (int i = 0; i < n; i++) {
- scanf("%d %d %d", &u, &v, &y);
- if (g.is_reachable(u, y) && g.is_reachable(v, y) && !g.others_leading(u, v, y)) printf("honest\n");
- else printf("liar\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement