国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

食物鏈 洛谷2024 并查集

2019-11-11 06:07:59
字體:
供稿:網(wǎng)友

題目描述


動物王國中有三類動物 A,B,C,這三類動物的食物鏈構(gòu)成了有趣的環(huán)形。A 吃 B,B 吃 C,C 吃 A。 現(xiàn)有 N 個動物,以 1 - N 編號。每個動物都是 A,B,C 中的一種,但是我們并不知道 它到底是哪一種。 有人用兩種說法對這 N 個動物所構(gòu)成的食物鏈關(guān)系進行描述: 第一種說法是“1 X Y”,表示 X 和 Y 是同類。 第二種說法是“2 X Y”,表示 X 吃 Y 。 此人對 N 個動物,用上述兩種說法,一句接一句地說出 K 句話,這 K 句話有的是真 的,有的是假的。當一句話滿足下列三條之一時,這句話就是假話,否則就是真話。 ? 當前的話與前面的某些真的話沖突,就是假話 ? 當前的話中 X 或 Y 比 N 大,就是假話 ? 當前的話表示 X 吃 X,就是假話 你的任務是根據(jù)給定的 N 和 K 句話,輸出假話的總數(shù)。

輸入輸出格式


輸入格式:


從 eat.in 中輸入數(shù)據(jù) 第一行兩個整數(shù),N,K,表示有 N 個動物,K 句話。 第二行開始每行一句話(按照題目要求,見樣例)

輸出格式:


輸出到 eat.out 中 一行,一個整數(shù),表示假話的總數(shù)。

輸入輸出樣例


輸入樣例#1:


100 7 1 101 1 2 1 2 2 2 3 2 3 3 1 1 3 2 3 1 1 5 5

輸出樣例#1:


3

說明


1 ≤ N ≤ 5 ? 10^4 1 ≤ K ≤ 10^5

Analysis


把動物關(guān)系分成三類,a是它本身,a+n是它吃什么,a+n+n是什么吃它 然后就各種判斷啊,同一類的合并,例如a吃b,那么a+n和b實際上是同一類動物,合并,以此類推 switch要用break啊記住記住要死要死 這題似乎是初二要求做的例題?現(xiàn)在補上

Code


#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <iostream>#include <algorithm>#include <string>#include <vector>#include <deque>#include <list>#include <set>#include <map>#include <stack>#include <queue>#include <numeric>#include <iomanip>#include <bitset>#include <sstream>#include <fstream>#define debug puts("-----")#define rep(i, st, ed) for (int i = st; i <= ed; i += 1)#define drp(i, st, ed) for (int i = st; i >= ed; i -= 1)#define fill(x, t) memset(x, t, sizeof(x))#define min(x, y) x<y?x:y#define max(x, y) x>y?x:y#define PI (acos(-1.0))#define EPS (1e-8)#define INF (1<<30)#define ll long long#define db double#define ld long double#define N 100001#define E N * 8 + 1#define MOD 100000007#define L 255using namespace std;int fa[N * 3 + 1];inline int read(){ int x = 0, v = 1; char ch = getchar(); while (ch < '0' || ch > '9'){ if (ch == '-'){ v = -1; } ch = getchar(); } while (ch <= '9' && ch >= '0'){ x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); } return x * v;}inline int getFather(const int &now){ return now == fa[now]? now: fa[now] = getFather(fa[now]);}inline int merge(const int &x, const int &y){ int fx = getFather(x), fy = getFather(y); if (fx ^ fy){ fa[fx] = fy; return 1; } return 0;}int main(void){ int n = read(), k = read(); int ans = 0; rep(i, 1, n + n + n){ fa[i] = i; } rep(i, 1, k){ int opt = read(), x = read(), y = read(); if (x > n || y > n){ ans += 1; //
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 寻甸| 乌海市| 抚州市| 会同县| 沐川县| 重庆市| 秀山| 宣武区| 临泉县| 北京市| 阿巴嘎旗| 江陵县| 项城市| 偃师市| 乐安县| 延庆县| 崇州市| 寿光市| 天祝| 固始县| 平潭县| 读书| 修武县| 平武县| 尼玛县| 屯留县| 巴东县| 玛曲县| 酉阳| 河西区| 中卫市| 托克托县| 阳江市| 中山市| 涞水县| 望谟县| 博野县| 天气| 龙井市| 新津县| 新丰县|