B - Neither shaken nor stirred URAL - 2013 (dfs)

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 imin 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 in i1, n i2, …, n imi are the numbers of the bars friends can go to right after leaving bar i (1 ≤ n ij ≤ nn 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

inputoutput
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

题意:

给定n个点的有向图:

下面n行,第一个数字表示点权,后面一个数字m表示有m条边。

起点是1.

对于每个点,输出2个值表示前驱点权1和该点点权2。

1、若有多条路径到达该点且前驱的点权存在>0则输出unknown,否则输出前驱的点权(就是若有多条路径且全为0输出0,否则若只有一条路径则输出前驱点权,否则输出unknown)

2、若1输出的是0,则输出该点点权,否则若该点点权>0输出该点点权,否则输出前驱点权。

==略繁琐

代码:


//Full of love and hope for life
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define inf 0x3f3f3f3f
//https://paste.ubuntu.com/

using namespace std;

typedef long long ll;
const int N = 1e5+5;
vector<int> ve[N];
int a[N],ans[N];
/*
template <class T>

inline bool rd(T &ret){
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return 0;
    while (c != '-' && (c<'0' || c>'9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}

template <class T>

inline void pt(T x){
    if (x <0){
        putchar('-');
        x = -x;
    }
    if (x>9) pt(x / 10);
    putchar(x % 10 + '0');
}
*/
void dfs(int pos,int num) {
    if(ans[pos]==-2){
        return ;
    }
    if(!ans[pos]){
        ans[pos]=num;
    }
    else{
        ans[pos]=-2;
    }
    if(a[pos]){
        num=a[pos];
    }

    for( auto it : ve[pos]){
        if(ans[it]!=num)
           dfs(it,num);
    }
}

int main()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        int x;
        cin >> x;
        while(x--){
            int y;
            cin >> y;
            ve[i].push_back(y);
        }
    }
    dfs(1,-1);
    for(int i=1;i<=n;i++){
        if(ans[i]==-1){
            cout << "sober ";
        }
        else if(ans[i]==-2){
            cout << "unknown ";
        }
        else{
            cout << ans[i] << " ";
        }
        if(a[i]){
            cout << a[i] << endl;
        }
        else{
            if(ans[i]==-1){
                cout << "sober" << endl;
            }
            else if(ans[i]==-2){
                cout << "unknown" << endl;
            }
            else{
                cout << ans[i] << endl;
            }
        }
    }
    return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZZ --瑞 hopeACMer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值