poj 3259 Wormholes

Description

While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that is BEFORE you entered the wormhole! Each of FJ's farms comprises N (1 ≤ N ≤ 500) fields conveniently numbered 1..NM (1 ≤ M ≤ 2500) paths, and W (1 ≤ W ≤ 200) wormholes.

As FJ is an avid time-traveling fan, he wants to do the following: start at some field, travel through some paths and wormholes, and return to the starting field a time before his initial departure. Perhaps he will be able to meet himself :) .

To help FJ find out whether this is possible or not, he will supply you with complete maps to F (1 ≤ F ≤ 5) of his farms. No paths will take longer than 10,000 seconds to travel and no wormhole can bring FJ back in time by more than 10,000 seconds.

Input

Line 1: A single integer, FF farm descriptions follow. 
Line 1 of each farm: Three space-separated integers respectively: NM, and W 
Lines 2..M+1 of each farm: Three space-separated numbers (SET) that describe, respectively: a bidirectional path between S and E that requires T seconds to traverse. Two fields might be connected by more than one path. 
Lines M+2..M+W+1 of each farm: Three space-separated numbers (SET) that describe, respectively: A one way path from S to E that also moves the traveler back T seconds.

Output

Lines 1..F: For each farm, output "YES" if FJ can achieve his goal, otherwise output "NO" (do not include the quotes).

Sample Input

2
3 3 1
1 2 2
1 3 4
2 3 1
3 1 3
3 2 1
1 2 3
2 3 4
3 1 8

Sample Output

NO
YES

Hint

For farm 1, FJ cannot travel back in time. 
For farm 2, FJ could travel back in time by the cycle 1->2->3->1, arriving back at his starting location 1 second before he leaves. He could start from anywhere on the cycle to accomplish this.

题意分析:大体意思就是有f个农场,有n个点,有m条双向路,有w个单向虫洞连接着个点,构造最短路径,看是否存在负环,就是通过虫洞倒退时间看能够存在负数环,来使一个点的出发时间小于到达时间,用bellman就可以过

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
#define ll long long
const int maxn=5202;
struct node{
    int u,v,w;
};
node edge[maxn];
 int n,m,p,dist[maxn],k;
void addedge(int u,int v,int w)
{
    edge[k].u=u;
    edge[k].v=v;
    edge[k].w=w;
    k++;
}
bool bellman_ford()
{
    int i,j;
    memset(dist,0,sizeof(dist));
    for (i=1;i<=n;i++)
        for (j=0;j<k;j++)
            if (dist[edge[j].u]+edge[j].w<dist[edge[j].v])
                 dist[edge[j].v]=dist[edge[j].u]+edge[j].w;
    for (j=0;j<k;j++)
         if (dist[edge[j].u]+edge[j].w<dist[edge[j].v])
            return 0;
    return 1;
}
int main()
{
    int t;
    int i,u,v,w;
    scanf("%d",&t);
    while (t--)
    {
        k=0;
        scanf("%d%d%d",&n,&m,&p);
        for (i=0;i<m;i++)
        {
            scanf("%d%d%d",&u,&v,&w);
            addedge(u,v,w);
            addedge(v,u,w);
        }
        for (i=0;i<p;i++)
        {
            scanf("%d%d%d",&u,&v,&w);
            addedge(u,v,-w);
        }
        if (bellman_ford()==0)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

spfa算法一样

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
#define ll long long
const int INF=1<<30;
const int maxn=5202;
struct node{
    int v,w,next;
};
node edge[maxn];
int m,n,p,k,dist[maxn],head[maxn],cnt[maxn];
bool vis[maxn];
void addedge(int u,int v,int w)
{
    edge[k].v=v;
    edge[k].w=w;
    edge[k].next=head[u];
    head[u]=k++;
}
bool spfa()
{
    int i;
    memset(vis,0,sizeof(vis));
    memset(cnt,0,sizeof(cnt));
    for (i=0;i<k;i++)
        dist[i]=INF;
    cnt[1]++;
    dist[1]=0;
    vis[1]=1;
    queue<int>q;
    q.push(1);
    while (!q.empty())
    {
        int x=q.front();
        q.pop();
        vis[x]=0;
        for (int e=head[x];e!=-1;e=edge[e].next)
        {
            if (dist[edge[e].v]>dist[x]+edge[e].w)
            {
                dist[edge[e].v]=dist[x]+edge[e].w;
                if (!vis[edge[e].v])
                {
                    q.push(edge[e].v);
                    vis[edge[e].v]=1;
                    cnt[edge[e].v]++;
                    if (cnt[edge[e].v]>=n)
                        return 0;
                }
            }
        }
    }
    return 1;
}
int main()
{
   int t,i,j,u,v,w;
   scanf("%d",&t);
   while (t--)
   {
       k=0;
     scanf("%d%d%d",&n,&m,&p);
     memset(head,-1,sizeof(head));
       for (i=0;i<m;i++)
       {
           scanf("%d%d%d",&u,&v,&w);
           addedge(u,v,w);
           addedge(v,u,w);
       }
       for (i=0;i<p;i++)
       {
           scanf("%d%d%d",&u,&v,&w);
           addedge(u,v,-w);
       }
       if (spfa())
        printf("NO\n");
       else
        printf("YES\n");
   }
    return 0;
}


内容概要:该研究通过在黑龙江省某示范村进行24小时实地测试,比较了燃煤炉具与自动/手动进料生物质炉具的污染物排放特征。结果显示,生物质炉具相比燃煤炉具显著降低了PM2.5、CO和SO2的排放(自动进料分别降低41.2%、54.3%、40.0%;手动进料降低35.3%、22.1%、20.0%),但NOx排放未降低甚至有所增加。研究还发现,经济性和便利性是影响生物质炉具推广的重要因素。该研究不仅提供了实际排放数据支持,还通过Python代码详细复现了排放特征比较、减排效果计算和结果可视化,进一步探讨了燃料性质、动态排放特征、碳平衡计算以及政策建议。 适合人群:从事环境科学研究的学者、政府环保部门工作人员、能源政策制定者、关注农村能源转型的社会人士。 使用场景及目标:①评估生物质炉具在农村地区的推广潜力;②为政策制定者提供科学依据,优化补贴政策;③帮助研究人员深入了解生物质炉具的排放特征和技术改进方向;④为企业研发更高效的生物质炉具提供参考。 其他说明:该研究通过大量数据分析和模拟,揭示了生物质炉具在实际应用中的优点和挑战,特别是NOx排放增加的问题。研究还提出了多项具体的技术改进方向和政策建议,如优化进料方式、提高热效率、建设本地颗粒厂等,为生物质炉具的广泛推广提供了可行路径。此外,研究还开发了一个智能政策建议生成系统,可以根据不同地区的特征定制化生成政策建议,为农村能源转型提供了有力支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值