版本比较
题解:CF240E Road Repairs
正文
增加 8 行删除 93 行
11233455678991011111213131415161718192021222324252627282930161718193 行未改动23242526424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111122728293031129 行未改动全部展开161162163164250165这似乎是一道最小树形图输出方案的模版题喵。这似乎是一道最小树形图输出方案的模版题。## 题意给你一只有 `n` 个点 `m` 条边的有向图,每条边的边权为 `0` 或 `1`。给你一只有 $n$ 个点 $m$ 条边的有向图,每条边的边权为 $0$ 或 $1$ 。
要求以 `1` 为根的 ~~超可爱~~ 最小树形图,并输出 ~~超可爱~~ 最小树形图中所有边权为 `1` 的边。无解输出 `-1`。要求以 $1$ 为根的最小树形图,并输出最小树形图中所有边权为 $1$ 的边。无解输出 $-1$。
注意到有输入输出文件 ~~(我是绝对不会说我在这上面卡了十分钟,看了讨论区才发现的)~~。## 思路正如开头所说的,这几乎是一道模版题,所以直接套用 [这题](https://www.luogu.com.cn/problem/P4716) 的代码即可,但是注意一下方案输出的方法:正如开头所说的,这几乎是一道模版题,所以如果不会最小树形图请先左转至 [这题](https://www.luogu.com.cn/problem/P4716) 学习基础的 `tarjan` 优化朱刘算法,这里就只讲一下方案输出的方法:
在进行 `tarjan` 的时候,我们每次会将一只可爱的环给 ~~暴力~~ 拆开,而拆开时的边就是我们选中的边。在进行 `tarjan` 的时候,我们每次会将一只环给 ~~暴力~~ 拆开,而拆开时的边就是我们选中的边。
所以我们只需要记录一下每次拆的时候边的编号等信息即可喵,具体实现看代码喵。所以我们只需要记录一下每次拆的时候边的编号等信息即可,具体实现可以看代码喵。## Code```cpp// I often find myself reminiscing about the past.// Moments of life freeze in my mind.// I cut, fold, and curl the time behind me, kneading it into the white clouds drifting across the sky.// Even clouds have their distinctions: cumulus clouds are heavy, while cirrus clouds are ethereal.// The moments in life that strike me with awe pass through my thoughts and remain unforgettable forever, while the more ordinary, everyday memories leave behind only fragments under the erosion of time.// Reminiscence is like entering a dream—too clear, and it cannot delight my imagination; too vague, and it sinks into nothingness.// Only the mist-shrouded mountains and rivers, the veiled woman—that perfect haziness—can satisfy my longing for beauty.// Reminiscence always wraps me, unbidden, in the yellowed pages of the past.// Friends parted and reunited, streets demolished and rebuilt—each clue helps me set out from a specific moment and sail upstream against the river of time.// The days gone by cannot be relived; I am merely a passerby.// Yet I still long to leave myself moments of leisure on every journey into memory—to pause before a scene, to gaze across the haze of years at my former self, and to savor as much sweetness as I can.// If beautiful times once flowed through my body, I am already content.// The past has solidified.// I carry my memories forward, but I often neglect to tend to them, and so the memories themselves keep changing their forms.// This brings a certain challenge to my journeys of recollection.// Where should I linger? I ask myself.
#include <bits/stdc++.h>// #define LOCAL3 行未改动// #define int long longusing pii = std::pair <int, int>;using ll = long long;
namespace ly { // 苦情巨树啊 // 你听见了吗 // 如果我也已经爱上了他 // 我愿意用我们相识的一点一滴以及我的全部妖力来起誓 // 让我们来生相见吧 namespace IO { #ifndef LOCAL constexpr auto maxn = 1 << 21; char in[maxn], out[maxn], *p1 = in, *p2 = in, *p3 = out; #define getchar() (p1 == p2 && (p2 = (p1 = in) + fread(in, 1, maxn, stdin), p1 == p2) ? EOF : *p1++) #define flush() (fwrite(out, 1, p3 - out, stdout)) #define putchar(x) (p3 == out + maxn && (flush(), p3 = out), *p3++ = (x)) class Flush{ public: ~Flush(){ flush(); } } _; #endif namespace usr { template <typename type> inline type read(type &x){ x = 0; bool flag(0); char ch = getchar(); while(!isdigit(ch)) flag ^= ch == '-', ch = getchar(); while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); return flag ? x = -x : x; } template <typename type> inline void write(type x){ x < 0 ? x = -x, putchar('-') : 0; static short Stack[50], top(0); do Stack[++top] = x % 10, x /= 10; while(x); while(top) putchar(Stack[top--] | 48); } inline char read(char &x){ do x = getchar(); while(isspace(x)); return x; } inline char write(const char &x){ return putchar(x); } inline void read(char *x){ static char ch; read(ch); do *(x++) = ch; while(!isspace(ch = getchar()) && ~ch); } template <typename type> inline void write(type *x){ while(*x) putchar(*(x++)); } inline void read(std::string &x){ static char ch; read(ch), x.clear(); do x += ch; while(!isspace(ch = getchar()) && ~ch); } inline void write(const std::string &x){ for(int i = 0, len = x.length(); i < len; ++i) putchar(x[i]); } template <typename type, typename...T> inline void read(type &x, T&...y){ read(x), read(y...); } template <typename type, typename...T> inline void write(const type &x, const T&...y){ write(x), putchar(' '), write(y...), sizeof...(y) ^ 1 ? 0 : putchar('\n'); } template <typename type> inline void put(const type &x, bool flag = 0){ write(x), flag ? putchar('\n') : putchar(' '); } } #ifndef LOCAL #undef getchar #undef flush #undef putchar #endif } using namespace IO::usr;} using namespace ly::IO::usr;// 已省略过长的快读喵
constexpr int N = 1e5 + 5;struct Heap{ int tot;129 行未改动全部展开// 阿乌拉,投降吧// ......// 阿乌拉,站在你面前的是活了上千年的魔法使```如有不对的地方喵,还请通融一下喵,熬夜写的时候脑子笨笨的喵。如有不对的地方,还请通融一下,熬夜写的时候脑子笨笨的。