http://codeforces.com/contest/160/problem/D

base on 克鲁斯卡尔,

首先每次都是对权值相同的边进行统一处理,假如加入了当前这条边出现了回路,那就能确定这条边是none的。

否则,让它加入进图,(先不合并),然后找到这个图的桥,那些就是any的,其他都是at least one的。

唯一要注意的就是不能像克鲁斯卡尔这样,没加入一条边,都合并。这里是把权值相同的边加入来后,再统一合并。

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

any
any
any
none

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
const int maxn = 1e5 + ;
int first[maxn], num;
struct Edge {
int u, v, w, id, tonext;
}e[maxn * ];
void addEdge(int u, int v, int w, int id) {
e[num].u = u, e[num].v = v, e[num].w = w, e[num].id = id, e[num].tonext = first[u];
first[u] = num++;
}
struct Node {
int u, v, w, id;
}data[maxn];
bool cmp1(struct Node a, struct Node b) {
return a.w < b.w;
}
int fa[maxn];
int tofind(int x) {
if (fa[x] == x) return x;
else return fa[x] = tofind(fa[x]);
}
char ans[][] = {"none", "any", "at least one"};
int res[maxn], in[maxn];
int DFN[maxn], low[maxn], when, vis[maxn];
void dfs(int cur, int fromID) {
DFN[cur] = low[cur] = ++when;
for (int i = first[cur]; ~i; i = e[i].tonext) {
int v = e[i].v;
if (e[i].id == fromID) continue;
vis[e[i].id] = true;
if (!DFN[v]) {
dfs(v, e[i].id);
low[cur] = min(low[cur], low[v]);
if (low[v] > DFN[cur]) {
res[e[i].id] = ;
}
} else low[cur] = min(low[cur], DFN[v]);
}
}
void work() {
num = ;
memset(first, -, sizeof first);
for (int i = ; i <= maxn - ; ++i) fa[i] = i;
int n, m;
cin >> n >> m;
for (int i = ; i <= m; ++i) {
cin >> data[i].u >> data[i].v >> data[i].w;
data[i].id = i;
}
sort(data + , data + + m, cmp1);
for (int i = ; i <= m;) {
int en;
for (en = i + ; en <= m && data[en].w == data[i].w; ++en);
for (int j = i; j < en; ++j) {
int x = tofind(data[j].u), y = tofind(data[j].v);
if (x == y) continue;
addEdge(x, y, data[j].w, data[j].id);
addEdge(y, x, data[j].w, data[j].id);
res[data[j].id] = ;
in[data[j].id] = true;
}
for (int j = i; j < en; ++j) {
if (vis[data[j].id] || !in[data[j].id]) continue;
vis[data[j].id] = true;
dfs(tofind(data[j].u), -);
}
for (int j = i; j < en; ++j) {
int x = tofind(data[j].u), y = tofind(data[j].v);
if (x != y) {
fa[y] = x;
first[x] = first[y] = -;
DFN[x] = DFN[y] = low[x] = low[y] = false;
when = ;
}
}
i = en;
}
for (int i = ; i <= m; ++i) {
cout << ans[res[i]] << endl;
}
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
IOS;
work();
return ;
}

D. Edges in MST 图论的更多相关文章

  1. Codeforces 160D Edges in MST tarjan找桥

    Edges in MST 在用克鲁斯卡尔求MST的时候, 每个权值的边分为一类, 然后将每类的图建出来, 那些桥就是必须有的, 不是桥就不是必须有. #include<bits/stdc++.h ...

  2. Codeforces 160 D. Edges in MST

    \(>Codeforces \space 160 D. Edges in MST<\) 题目大意 : 给出一张带权无向图,求对于这张图上的每一条边,其是必然存在于每一种最小生成树中,还是至 ...

  3. [CF160D]Edges in MST

    [CF160D]Edges in MST 题目大意: 一个\(n(n\le10^5)\)个点,\(m(m\le10^5)\)条边的连通图.对于图中的每条边,判断它与该图最小生成树的关系: 在该图所有的 ...

  4. [CF160D]Edges in MST (最小生成树+LCA+差分)

    待填坑 Code //CF160D Edges in MST //Apr,4th,2018 //树上差分+LCA+MST #include<cstdio> #include<iost ...

  5. Codeforces Round #599 (Div. 1) B. 0-1 MST 图论

    D. 0-1 MST Ujan has a lot of useless stuff in his drawers, a considerable part of which are his math ...

  6. CF 160D Edges in MST 最小生成树的性质,寻桥,缩点,批量处理 难度:3

    http://codeforces.com/problemset/problem/160/D 这道题要求哪条边存在于某个最小生成树中,哪条边不存在于最小生成树中,哪条边绝对存在于最小生成树中 明显桥边 ...

  7. 清北学堂(2019 5 2) part 5

    今天讲图论,顺便搞一搞之前没弄完的前向星dij 1.图的基本概念(课件原话): G (图)= (V(点); E(边)) 一般来说,图的存储难度主要在记录边的信息 无向图的存储中,只需要将一条无向边拆成 ...

  8. Codeforces Round #111 (Div. 2)

    Codeforces Round #111 (Div. 2) C. Find Pair 题意 给\(N(N \le 10^5)\)个数,在所有\(N^2\)对数中求第\(K(K \le N^2)\)对 ...

  9. 算法8-4:Kruskal算法

    Kruskal算法用于计算一个图的最小生成树.这个算法的过程例如以下: 依照边的权重从小到达进行排序 依次将每条边添加到最小生成树中,除非这条边会造成回路 实现思路 第一个步骤须要对边进行排序,排序方 ...

随机推荐

  1. Python实现结对编程项目

    Github (李昆乘)(陈俊豪) 开发流程 PSP2.1 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning 计划 ...

  2. C/C++语法知识点汇总

    *  静态局部变量,在不同函数中可以同名. 静态全局变量,在不同文件中可以同名. 静态函数,在不同文件中可以同名. *  普通全局变量和普通函数,在同一工程中不能同名. 在相链接的程序与库之间,可以同 ...

  3. Maven-将jar包安装到本地仓库

    因为项目需要,使用的是sqlserver数据库,但是却找不到其对应的pom依赖,所以需要将本地jar包安装到本地仓库,定义pom依赖.以此为例,其他jar包均可参考该方式 cmd命令语句: mvn i ...

  4. ICE 迁移64位安装问题

    昨天手贱,在apt-get install 后有一大堆,上百个安装包not upgrade, 发现有提示apt-get autoremove,犹豫了很久后还是忍不住执行了autoremove:这个命令 ...

  5. BZOJ1453:[WC]Dface双面棋盘

    浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:https://lydsy.com/JudgeOnline/problem. ...

  6. 用Spring MVC开发简单的Web应用程序

    1 工具与环境 借助Eclipse4.3 + Maven3.0.3构建Java Web应用程序.使用Maven内置的servlet 容器jetty,不需手工集成Web服务器到Eclipse.还帮我们自 ...

  7. NSCLIENT++可以采集的指标

    Documentation   Information   Commands/Modules   CheckDisk   CheckFileSize   CheckDriveSize   CheckF ...

  8. 继承HibernateDaoSupport实现DAO(spring整合hibernate)

    转自:https://blog.csdn.net/yz9612/article/details/80234377 spring为hibernate的DAO提供工具类:HibernateDaoSuppo ...

  9. 【244】◀▶IEW-Unit09

    Unit 9 Food 1)Model1题目及范文讲解 In the world today, there is a problem with food production. As a result ...

  10. Ubuntu 14.04中修复默认启用HDMI后没有声音的问题

    声音问题在Ubuntu中是老生常谈了.先前我已经在修复Ubuntu中的“无声”问题一文中写到了多种方法,但是我在此正要谈及的声音问题跟在另外一篇文章中提到的有所不同. 因此,我安装了Ubuntu 14 ...