传送门

Luogu

解题思路

首先对于所有不属于任何一条路径上的边,它的权值是任意的。

对于所有在路径上的边 \((u,v)\) 满足 \(1\le dis_v-dis_u\le2\)

差分约束即可。

细节注意事项

  • 用dfs判负环时注意一下时间效率

参考代码

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <vector>
#include <cmath>
#include <ctime>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= (c == '-'), c = getchar();
while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
s = f ? -s : s;
} const int _ = 1010;
const int __ = 5010 * 2 + 1010; int n, m, vis[_], dis[_], exi[_];
struct edge{ int x, y; }g[__];
vector < int > G1[_], G2[_];
int tot, head[_], nxt[__], ver[__], w[__];
inline void Add_edge(int u, int v, int d)
{ nxt[++tot] = head[u], head[u] = tot, ver[tot] = v, w[tot] = d; } inline int check(int i) { return vis[g[i].x] == 3 && vis[g[i].y] == 3; } inline int spfa(int u) {
exi[u] = 1;
for (rg int i = head[u]; i; i = nxt[i]) {
int v = ver[i];
if (dis[v] < dis[u] + w[i]) {
dis[v] = dis[u] + w[i];
if (exi[v]) return 0;
if (!spfa(v)) return 0;
}
}
exi[u] = 0;
return 1;
} inline void dfs1(int u) { vis[u] |= 1; for (rg int v : G1[u]) if (!(vis[v] & 1)) dfs1(v); } inline void dfs2(int u) { vis[u] |= 2; for (rg int v : G2[u]) if (!(vis[v] & 2)) dfs2(v); } int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
read(n), read(m);
for (rg int u, v, i = 1; i <= m; ++i)
read(u), read(v), G1[u].push_back(v), G2[v].push_back(u), g[i] = (edge) { u, v };
dfs1(1), dfs2(n);
for (rg int i = 1; i <= m; ++i)
if (check(i)) Add_edge(g[i].x, g[i].y, 1), Add_edge(g[i].y, g[i].x, -2);
for (rg int i = 1; i <= n; ++i) Add_edge(0, i, 0), dis[i] = -0x3f3f3f3f;
if (!spfa(0)) return puts("No"), 0;
puts("Yes");
for (rg int i = 1; i <= m; ++i) {
if (check(i)) printf("%d\n", dis[g[i].y] - dis[g[i].x]);
else puts("1");
}
return 0;
}

完结撒花 \(qwq\)

「CF241E」Flights的更多相关文章

  1. 「CF576D」 Flights for Regular Customers

    「CF576D」 Flights for Regular Customers 对不起我又想网络流去了 你看这长得多像啊,走过至少多少条边就是流量下界,然后没上界 但是这个题求的最少走多少条边啊...完 ...

  2. 「译」JUnit 5 系列:条件测试

    原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...

  3. 「译」JUnit 5 系列:扩展模型(Extension Model)

    原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...

  4. JavaScript OOP 之「创建对象」

    工厂模式 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程.工厂模式虽然解决了创建多个相似对象的问题,但却没有解决对象识别的问题. function createPers ...

  5. 「C++」理解智能指针

    维基百科上面对于「智能指针」是这样描述的: 智能指针(英语:Smart pointer)是一种抽象的数据类型.在程序设计中,它通常是经由类型模板(class template)来实做,借由模板(tem ...

  6. 「JavaScript」四种跨域方式详解

    超详细并且带 Demo 的 JavaScript 跨域指南来了! 本文基于你了解 JavaScript 的同源策略,并且了解使用跨域跨域的理由. 1. JSONP 首先要介绍的跨域方法必然是 JSON ...

  7. 「2014-5-31」Z-Stack - Modification of Zigbee Device Object for better network access management

    写一份赏心悦目的工程文档,是很困难的事情.若想写得完善,不仅得用对工具(use the right tools),注重文笔,还得投入大把时间,真心是一件难度颇高的事情.但,若是真写好了,也是善莫大焉: ...

  8. 「2014-3-18」multi-pattern string match using aho-corasick

    我是擅(倾)长(向)把一篇文章写成杂文的.毕竟,写博客记录生活点滴,比不得发 paper,要求字斟句酌八股结构到位:风格偏杂文一点,也是没人拒稿的.这么说来,arxiv 就好比是 paper 世界的博 ...

  9. 「2014-3-17」C pointer again …

    记录一个比较基础的东东-- C 语言的指针,一直让人又爱又恨,爱它的人觉得它既灵活又强大,恨它的人觉得它太过于灵活太过于强大以至于容易将人绕晕.最早接触 C 语言,还是在刚进入大学的时候,算起来有好些 ...

随机推荐

  1. How to make mail more effectively?

    1.What does your reader need to know? 2.What does your reader know already? 3.Will your reader be ab ...

  2. E. Vus the Cossack and a Field (求一有规律矩形区域值) (有一结论待证)

    E. Vus the Cossack and a Field (求一有规律矩形区域值) 题意:给出一个原01矩阵,它按照以下规则拓展:向右和下拓展一个相同大小的 0 1 分别和原矩阵对应位置相反的矩阵 ...

  3. ansible笔记(11):tags的用法

    你写了一个很长的playbook,其中有很多的任务,这并没有什么问题,不过在实际使用这个剧本时,你可能只是想要执行其中的一部分任务而已,或者,你只想要执行其中一类任务而已,而并非想要执行整个剧本中的全 ...

  4. chrome firefox浏览器屏蔽百度热搜

    我是原文 操作 点击拦截元素,然后选择页面元素,添加

  5. sqlserver 数据保留固定位小数,四舍五入后保存

    在实际业务中遇到金额保留四舍五入后,保留两位小数的需求.但是原来的数据是保留的6位小数,所以需要转化一下.具体实现过程如下: EG:SELECT CAST ( ROUND(1965.12540,2) ...

  6. win7搭建python环境--同时安装版本2和版本3

    软件准备[以win7 64位系统为例] python2.x版本建议使用2.7.9或更新版本,因为该版本开始集成了setuptools和pip,这样省去了不少功夫 python2.7.9下载地址: ht ...

  7. Git - git bash 在 windows 下创建软连接

    1. 概述 使用 git bash 在 windows 下创建软连接 或者叫 快捷方式 感谢 Tony 老师的帮助 Tony 的技术笔记 Windows 使用 ln -s 创建软链接 2. 问题 需求 ...

  8. 【资源分享】Half-Life(半条命)中英版

    *----------------------------------------------[下载区]----------------------------------------------* ...

  9. 每天进步一点点------Sobel算子(1)

    void MySobel(IplImage* gray, IplImage* gradient) { /* Sobel template a00 a01 a02 a10 a11 a12 a20 a21 ...

  10. js jquery 页面初始化加载

    一.js 页面加载初始化方法 // 1.在body里面写初始化方法. <body onload='init()'> </body> <script type=" ...