The ACM ICPC regional contest in St. Petersburg is a stressful event even for veterans of competetive programming. That’s why for the last four years programmer Denchik and his coach Vova go to their favorite bars to relax after the event. Having entered a bar, Denchik immediately orders cocktail “B-52”. If there is no such cocktail on the menu he drinks nothing. On the other hand, in places, where the cocktail is good, Denchik can repeat his order several times.
Vova, as an elder friend, tries to control his trainee drunkenness degree. When entering and leaving bars, Vova asks Denchik how many cocktails he has drunk in the last bar where B-52 was served. If Denchik is not sure about the answer, Vova considers Denchik’s drinking enough for this day and takes him to the hotel.
This year the story repeats again. Denchik has the experience of four previous regional contests and knows which bars serve B-52 and how many cocktails he’s going to drink in each bar at one visit. He also knows where they can go after leaving every bar on their route. For which bars Denchik may prepare right answers to Vova’s questions in advance, no matter what route they choose?
Input
The first line contains an integer n which is the number of bars (1 ≤ n ≤ 100 000). Next n lines describe these bars. The i-th line contains integers k i, mi, n i1, n i2, …, n imi (0 ≤ k i ≤ 100 000; 0 ≤ m i ≤ n). If k i equals zero, then in bar i B-52 is not served, and if k i is positive, it means that Denchik will drink k i cocktails at one visit to bar i. n i1, n i2, …, n imi are the numbers of the bars friends can go to right after leaving bar i (1 ≤ n ij ≤ n; n ij < ni,j+1). There can be number i among the numbers n ij, and it means that after leaving bar i friends can hang around and enter the same bar again. The sum of all numbers mi does not exceed 100 000.
The bars are numbered in the order they are in the input data. Bar with number 1 is the bar from which Vova and Denchik begin their journey. It is guaranteed that during the night friends can reach every bar listed in the input.
Output
In the i-th of n lines output Denchik’s answers to Vova’s question on entering bari and leaving it. Every answer should have one of the following forms:
- sober, if Denchik hasn’t drunk any B-52 yet
- X, if during the last visit to the bar where B-52 was served Denchik drunk Xcocktails (X is an integer from 1 to 100 000)
- unknown, if with different routes to the i-th bar different situations are possible
Example
input | output |
---|---|
5 0 2 2 3 6 1 4 5 2 4 5 5 1 5 0 0 | sober sober sober 6 sober 5 unknown 5 5 5 |
2 0 2 1 2 0 2 1 2 | sober sober sober sober |
题目.....不想解释了,自己翻译吧,嘻嘻
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
const double pi = acos(-1.0);
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 50;
int a[maxn];
vector<int> ve[maxn];
int zt[maxn];
int n;
void dfs(int pos, int y)
{
if(zt[pos] == -2) return ;
if(!zt[pos]) zt[pos] = y;
else zt[pos] = -2;
if(a[pos]) y = a[pos];
for(auto it : ve[pos])
{
if(zt[it] != y) dfs(it, y);
}
}
int main()
{
memset(zt, 0, sizeof(zt));
cin >> n;
for(int i=1; i<=n; i++)
{
cin >> a[i];
int x;
cin >> x;
for(int j=0; j<x; j++)
{
int y;
cin >> y;
ve[i].push_back(y);
}
}
dfs(1, -1);
for(int i=1; i<=n; i++)
{
if(zt[i] == -1) cout << "sober ";
else if(zt[i] == -2) cout << "unknown ";
else cout << zt[i] << ' ';
if(a[i] > 0) cout << a[i] << endl;
else
{
if(zt[i] == -1) cout << "sober" << endl;
else if(zt[i] == -2) cout << "unknown" << endl;
else cout << zt[i] << endl;
}
}
return 0;
}