URAL 1997 Those are not the droids you're looking for 二分图最大匹配

通过分析酒吧进出记录,判断是否存在非走私者或货主的访客。利用二分图匹配算法解决酒吧访客类型验证问题。

Those are not the droids you're looking for

题目连接:

http://acm.timus.ru/problem.aspx?space=1&num=1997

Description

Bar owner: Hey. We don’t serve their kind here.
Luke: What?
Bar owner: Your droids – they’ll have to wait outside. We don’t want them here.
Planet Tatooine is quite far from the center of the Galaxy. It is at the intersection of many hyperspace paths and it hosts smugglers and hoods of all sorts. The pilots who visited external territories have been to the space port bar called Mos Eisley for a drink at least once.
In this bar you can find a bunch of rascals and scoundrels from all over the Galaxy. The bar owner is ready to make drinks for any client except for, perhaps, a droid. Usually the bar has a lot of smugglers hanging out there. Each smuggler spends at least a minutes inside hoping to meet a good client. Cargo owners show up quite often as well. They usually find a dealer quickly, so they never spend more than b minutes in the bar.
The imperial stormtroopers are searching through Tatooine for the escaped droids. The bar owner said that no droids had ever been on his territory. He also said that nobody except for smugglers and cargo owners had been in the place recently.
Help the stormtroopers find out if the owner is a liar. For that, you are going to need the daily records from the sensor on the entrance door. The sensor keeps record of the time when somebody entered the bar or left it. The stormtroopers got the records after the bar had been closed, so there was nobody in the bar before or after the sensor took the records. You can assume that the sensor is working properly. That is, if somebody went through the bar door, the sensor made a record of that. You can also assume that the bar clients go in and out only through the door with the sensor. But the bar owner and the staff use the ‘staff only’ door.

Input

The first line of the input contains integers a and b (1 ≤ a, b ≤ 10 9, b + 1 < a). The second line contains integer n — the number of records from the sensor (2 ≤ n ≤ 1000). The i-th of the next n lines contains two integers ti and di (1 ≤ ti ≤ 10 9, di ∈ {0,1}) — the time of the i-th record and direction (0 — in the bar, 1 — out of the bar). The records in the input are listed in the increasing order of ti.

Output

If there is no doubt that somebody who was neither a smuggler nor a cargo owner visited the bar, print "Liar" on a single line. Otherwise, print a line "No reason". And in the following lines list information on all visitors of the bar. The information about a visitor consists of two space-separated numbers — the time this visitor entered the bar and the time he left the bar. If there are multiple solutions that correspond to the sensor records, print any of them.

Sample Input

6 3
4
1 0
2 0
5 1
10 1

Sample Output

No reason
1 10
2 5

Hint

题意

这个星球有两种人,一种人进酒吧至少玩a小时,一种人进酒吧最多玩b小时

现在给你这个酒吧进进出出的时间,问你是否存在一组合法解

题解:

显然的二分图匹配,把合法的进入和退出的,连一条边

然后去跑匈牙利就好了

最后输出一组解

代码

#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e3 + 15;
int a , b , n , idx[maxn] , vis[maxn] , Left[maxn] , halft[maxn] , harht[maxn];
vector < int > lft[maxn] , rht[maxn];
pair < int , int > p[maxn];

void Build_Graph(){
    int curlft = 0 ,  currht = 0;
    for(int i = 1 ; i <= n ; ++ i)
        if( p[i].second == 0 ){
            idx[i] = ++ curlft;
            halft[curlft] = i;
        }
        else{
            idx[i] = ++ currht;
            harht[currht] = i;
        }
    for(int i = 1 ; i <= n ; ++ i){
        for(int j = i + 1 ; j <= n ; ++ j){
            if(p[i].second == 0 && p[j].second == 1){
                if( p[j].first - p[i].first >= a){
                    lft[idx[i]].push_back( idx[j] );
                    rht[idx[j]].push_back( idx[i] );
                }
                if( p[j].first - p[i].first <= b){
                    lft[idx[i]].push_back( idx[j] );
                    rht[idx[j]].push_back( idx[i] );
                }
            }
        }
    }
}

int dfs(int x){
    for(auto it : lft[x]){
        if(Left[it] == -1){
            Left[it] = x;
            return 1;
        }
        if(vis[it]) continue;
        vis[it] = 1;
        if(dfs(Left[it])){
            Left[it] = x;
            return 1;
        }
    }
    return 0;
}

int main(int argc,char *argv[]){
    int t = 0;
    scanf("%d%d%d",&a,&b,&n);
    for(int i = 1 ; i <= n ; ++ i){
        scanf("%d%d",&p[i].first,&p[i].second);
        if( p[i].second == 0 ) t ++ ;
        else t--;
    }
    if( t ) printf("Liar\n");
    else{
        Build_Graph();
        int match = 0;
        memset(Left , -1 , sizeof( Left ) );
        for(int i = 1 ; i <= n / 2 ; ++ i){
            memset( vis , 0 , sizeof( vis ) );
            match += dfs( i );
        }
        if( match != n / 2 ) printf("Liar\n");
        else{
            printf("No reason\n");
            for(int i = 1 ; i <= n / 2 ; ++ i){
                int ri = harht[i] , li = halft[Left[i]];
                printf("%d %d\n" , p[li].first , p[ri].first );
            }
        }
    }
    return 0;
}
### URAL Networks介绍 URAL Networks代表一种专注于处理复杂结构化数据的神经网络架构,尤其适用于图形和其他非欧几里得域的数据。这类网络旨在解决传统深度学习方法难以应对的问题,在这些领域中,输入数据通常不是简单的向量或网格状排列的像素。 #### 图形上的卷积操作 对于图形上定义的任务,研究主要集中在如何有效地将卷积运算推广到这种不规则结构之上[^1]。具体来说: - **消息传递神经网络 (MPNN)** 是一类重要的模型,能够很好地捕捉节点间的关系并应用于多个科学计算场景,比如量子化学等领域。 - **非局部神经网络 (NLNN)** 则引入了自注意力机制来增强特征表达能力,尽管其具体的实现细节可能不如某些其他变体那样清晰界定。 - **图形网络 (GN) 框架** 不仅为现有GNNs提供了一个强有力的理论基础,同时也强调了通过适当的设计可以促进更广泛的泛化性能——这对于构建具备更强推理能力和鲁棒性的AI系统至关重要。 ```python import torch from torch_geometric.nn import MessagePassing, global_mean_pool class SimpleGraphConv(MessagePassing): def __init__(self, in_channels, out_channels): super(SimpleGraphConv, self).__init__() self.lin = torch.nn.Linear(in_channels, out_channels) def forward(self, x, edge_index): return self.propagate(edge_index, size=(x.size(0), x.size(0)), x=self.lin(x)) # Example usage of a simple graph convolution layer within an MPNN framework. ``` 上述代码片段展示了一个简化版的消息传递层实现方式,这是构成许多先进图神经网络的核心组件之一。 #### 应用实例 在实际应用方面,URAL Networks已经被成功部署到了诸如社交网络分析、推荐系统优化以及生物信息学等多个重要行业当中。特别是在涉及大规模异构交互模式识别的情况下表现出色。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值