POJ 2983 Is the Information Reliable? 差分约束

Time Limit: 3000MS Memory Limit: 131072K
Total Submissions: 14143 Accepted: 4439

Description

The galaxy war between the Empire Draco and the Commonwealth of Zibu broke out 3 years ago. Draco established a line of defense called Grot. Grot is a straight line with N defense stations. Because of the cooperation of the stations, Zibu’s Marine Glory cannot march any further but stay outside the line.

A mystery Information Group X benefits form selling information to both sides of the war. Today you the administrator of Zibu’s Intelligence Department got a piece of information about Grot’s defense stations’ arrangement from Information Group X. Your task is to determine whether the information is reliable.

The information consists of M tips. Each tip is either precise or vague.

Precise tip is in the form of P A B X, means defense station A is X light-years north of defense station B.

Vague tip is in the form of V A B, means defense station A is in the north of defense station B, at least 1 light-year, but the precise distance is unknown.

Input

There are several test cases in the input. Each test case starts with two integers N (0 < N ≤ 1000) and M (1 ≤ M ≤ 100000).The next M line each describe a tip, either in precise form or vague form.

Output

Output one line for each test case in the input. Output “Reliable” if It is possible to arrange N defense stations satisfying all the M tips, otherwise output “Unreliable”.

Sample Input

3 4
P 1 2 1
P 2 3 1
V 1 3
P 1 3 1
5 5
V 1 2
V 2 3
V 3 4
V 4 5
V 3 5

Sample Output

Unreliable
Reliable

Source

 

 

 

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<functional>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f
#define sf(x) scanf("%lld",&x)
const LL MAXN = 200050;
const LL MAXM = 1000050;
/*
查分约束系统
节点映射到y坐标系上!ti  为 i到原点的距离
V A B ta - tb>=1 tb - ta <= - 1
P A B X ta - tb >= X  tb - ta <= -X
节点性质可得:
ti - ti+1 <= 1

spfa 判断有没有负环 + 并查集 判断精确关系是否符合
*/
struct edge
{
    LL to, next, dist;
}E[MAXM];
LL tot, head[MAXN], dist[MAXN], cnt[MAXN];
LL n, m;
bool vis[MAXN];
inline void init()
{
    tot = 0;
    memset(head, -1, sizeof(head));
}
inline void addedge(LL u, LL v, LL d)
{
    E[tot].to = v;
    E[tot].dist = d;
    E[tot].next = head[u];
    head[u] = tot++;
}
bool spfa()
{
    memset(vis, false, sizeof(vis));
    memset(dist, INF, sizeof(dist));
    memset(cnt, 0, sizeof(cnt));
    queue<LL> q;
    q.push(0);
    vis[0] = true;
    dist[0] = 0;
    cnt[0] = 1;

    while (!q.empty())
    {
        LL f = q.front();
        q.pop();
        vis[f] = false;
        for (LL i = head[f]; i != -1; i = E[i].next)
        {
            LL v = E[i].to, d = E[i].dist;
            if (dist[v] > dist[f] + d)
            {
                dist[v] = dist[f] + d;
                if (!vis[v])
                {
                    vis[v] = true;
                    q.push(v);
                    if (++cnt[v] > n)
                        return false;
                }
            }

        }
    }
    return true;
}
int main()
{
    while (scanf("%lld%lld", &n, &m) != EOF)
    {
        init();
        //    bool f = false;
        char op[2];
        LL f, t, d;
        for (LL i = 0; i < m; i++)
        {
            scanf("%s", op);
            if (op[0] == 'P')
            {
                sf(f), sf(t), sf(d);
                addedge(t, f, -d);
                addedge(f, t, d);
            }
            else
            {
                sf(f), sf(t);
                addedge(t, f, -1);
            }
        }
        for (LL i = 1; i <= n; i++)
        {
            addedge(0, i, 0);
        }
        if (spfa())
            cout << "Reliable" << endl;
        else
            cout << "Unreliable" << endl;
    }
    return 0;
}

 也可不加附加节点

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<functional>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f
#define sf(x) scanf("%lld",&x)
const LL MAXN = 200050;
const LL MAXM = 1000050;
/*
查分约束系统
节点映射到y坐标系上!ti  为 i到原点的距离
V A B ta - tb>=1 tb - ta <= - 1
P A B X ta - tb >= X  tb - ta <= -X
节点性质可得:
ti - ti+1 <= 1

spfa 判断有没有负环 + 并查集 判断精确关系是否符合
*/
struct edge
{
    LL to, next, dist;
}E[MAXM];
LL tot, head[MAXN], dist[MAXN], cnt[MAXN];
LL n, m;
bool vis[MAXN];
inline void init()
{
    tot = 0;
    memset(head, -1, sizeof(head));
}
inline void addedge(LL u, LL v, LL d)
{
    E[tot].to = v;
    E[tot].dist = d;
    E[tot].next = head[u];
    head[u] = tot++;
}
bool spfa()
{
    memset(vis, false, sizeof(vis));
    memset(dist, INF, sizeof(dist));
    memset(cnt, 0, sizeof(cnt));
    queue<LL> q;
    for (int i = 1; i <= n; i++)
        q.push(i), vis[i] = true, dist[i] = 0;
    while (!q.empty())
    {
        LL f = q.front();
        q.pop();
        vis[f] = false;
        for (LL i = head[f]; i != -1; i = E[i].next)
        {
            LL v = E[i].to, d = E[i].dist;
            if (dist[v] > dist[f] + d)
            {
                dist[v] = dist[f] + d;
                if (!vis[v])
                {
                    vis[v] = true;
                    q.push(v);
                    if (++cnt[v] > n)
                        return false;
                }
            }

        }
    }
    return true;
}
int main()
{
    while (scanf("%lld%lld", &n, &m) != EOF)
    {
        init();
        //    bool f = false;
        char op[2];
        LL f, t, d;
        for (LL i = 0; i < m; i++)
        {
            scanf("%s", op);
            if (op[0] == 'P')
            {
                sf(f), sf(t), sf(d);
                addedge(t, f, -d);
                addedge(f, t, d);
            }
            else
            {
                sf(f), sf(t);
                addedge(t, f, -1);
            }
        }
        /*for (LL i = 1; i <= n; i++)
        {
            addedge(0, i, 0);
        }*/
        if (spfa())
            cout << "Reliable" << endl;
        else
            cout << "Unreliable" << endl;
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/joeylee97/p/7553472.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园建设方案旨在通过信息化手段提升教育、管理和服务水平,实现资源数字化、工作流程化、管理高效化和决策智能化。方案包括智慧校园信息化平台和安防平台的建设,涉及教学、科研、管理和服务等多个方面,以满足现代教育和培训需求。 技术服务要求强调了统一支撑平台的建设,包括数据标准、接口标准、代码标准和用户信息标准的统一制定。平台需满足信创和X86交叉适配要求,确保安全自主可控的系统开发环境。此外,方案还涵盖了用户中心系统、统一认证授权中心、统一工作流中心、统一智能报表中心等多个模块,以及数据共享中心、语音识别、移动服务终端等功能,以实现校园内外部信息的互联互通和资源共享。 智慧校园信息化平台的建设还包括了对教学管理、人事管理、公文管理、档案管理、即时通讯、会议管理、督办工作、资产管理等方面的数字化和自动化升级。这些模块的集成旨在提高工作效率,优化资源配置,加强监督管理,并通过移动应用等技术手段,实现随时随地的信息访问和业务处理。 安防平台的建设则侧重于校园安全,包括停车场管理、人脸识别测温、访客自助登记、视频监控等多个系统。这些系统的集成旨在提高校园的安全管理水平,实现对校园内外人员和车辆的有效监控和管理,确保校园环境的安全稳定。 最后,方案还提到了对固定资产的管理,包括购置、使用、归还、报废等全生命周期的管理,以及对网络设备、安防设备、服务器等硬件设施的配置和管理。通过这些措施,智慧校园建设方案旨在为校园提供一个安全、高效、便捷的学习和工作环境。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值