L2-010. 排座位(并查集)*
2024-08-26 05:58:37
#include<iostream>
#include<math.h>
using namespace std;
int a[];
int map[][];
int find(int t)
{
if(t!=a[t])
{
a[t]=find(a[t]);
}
return a[t];
}
int main()
{
int n,m,k,i;
cin>>n>>m>>k;
for(i=;i<=n;i++)
a[i]=i;
int x,y,z;
for(i=;i<=m;i++)
{
cin>>x>>y>>z;
map[x][y]=map[y][x]=z;
if(z==)
{
x=find(x);
y=find(y);
if(x!=y)
a[x]=y;
}
}
int t1,t2;
for(i=;i<=k;i++)
{
cin>>t1>>t2;
if(map[t1][t2]==)
{
cout<<"No problem"<<endl;
}
else if(map[t1][t2]==-)
{
if(find(t1)==find(t2))
cout<<"OK but..."<<endl;
else
cout<<"No way"<<endl;
}
else
{
cout<<"OK"<<endl;
}
}
}
最新文章
- c++字符串
- 上架到AppStore?第一次上架之路
- JS 关于(function( window, undefined ) {})(window)写法的理解
- javascript中比较数字大小
- 初识Winform , 还好没喜欢上控制台
- 另一种遍历Map的方式: Map.Entry 和 Map.entrySet()
- HDU5802-windows 10-dfs+贪心
- 淘宝(阿里百川)手机客户端开发日记第六篇 Service详解(六)
- 《JavaScript模式》第1章 简介
- compass(sass)+seajs+frozenui+frozenjs+svn主干分支
- java学习:用反射构造bean
- 如何学会web前端开发
- 无法在People Picker中选择用户
- docker managed volume - 每天5分钟玩转 Docker 容器技术(40)
- poj 3264 &; poj 3468(线段树)
- Linux SHELL中sh和bash的区别
- Linux IO 模型
- Dash VS Underscore
- gi常用命令
- git install
热门文章
- Objective-C不能以new开头命名属性
- lvs 初始 第一章
- vue 2.0 使用replace时要点击路由多次才能返回
- Cocos Creator 使用protobufjs
- [easyUI] datagrid 数据格 可以进行分页
- guxh的python笔记二:函数基础
- python实现http get请求
- 『TensorFlow』读书笔记_Inception_V3_上
- vs2013+qt5.3.2+pcl1.8.0+osg2.3开发环境配置
- 单点登录系统实现基于SpringBoot