Corporative Network UVA
来源:互联网 发布:网络世界边锋游戏 编辑:程序博客网 时间:2024/06/04 00:22
可能是数据水点,,直接查找都不会错
f [ i ] 代表 i 的 父结点, d [ i ] 表示 i 到 父结点的距离,每次进行查找
下篇博文 给出 压缩路径的做法,,耗时比较少,可应对更大数据量
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <set>#include <map>#include <stack>#include <queue>#include <ctype.h>#include <vector>#include <algorithm>#define in freopen("in.txt", "r", stdin)#define out freopen("out.txt", "w", stdout)// cout << " === " << endl;using namespace std;typedef long long ll;const int maxn = 20000 + 7, INF = 0x3f3f3f3f, mod = 1000; int T, n, ans;int f[maxn], d[maxn];void find_(int id) { if(id == f[id]) return ; ans += d[id]; find_(f[id]);}void solve() { char c; while(scanf("%c", &c)) { if(c == 'O') return; if(c == 'E') { int id; scanf("%d", &id); //st.insert(id); ans = 0; find_(id); printf("%d\n", ans); } else if(c == 'I') { int a_, b_; scanf("%d %d", &a_, &b_); f[a_] = b_; d[a_] = abs(a_-b_) % mod; } }}int main() { scanf("%d", &T); while(T--) { scanf("%d", &n); for(int i = 0; i <= n; ++i) f[i] = i, d[i] = 0; solve(); } return 0;}
阅读全文
1 0
- uva 1329 Corporative Network
- uva 1329 - Corporative Network
- UVA - 1329 Corporative Network
- UVA 1329 Corporative Network
- UVa 1329 Corporative Network
- UVa 1329 Corporative Network
- UVA 1329 corporative NetWork
- UVA 1329 - Corporative Network
- Uva 3027 Corporative Network
- UVA 1329 Corporative Network
- UVa 1329 - Corporative Network
- uva 1329 Corporative Network
- Corporative Network UVA
- Corporative Network UVA
- Corporative Network UVA
- Corporative Network UVA
- UVA 1329 Corporative Network
- Corporative Network UVA
- 注解
- GPIO_ReadOutputDataBit及GPIO_ReadInputDataBit区别
- ccf认证压缩编码
- iOS LRC校验
- 微信端服务器配置
- Corporative Network UVA
- iOS开发之内存缓存 磁盘缓存 沙盒
- poj1061青蛙的约会(扩展欧几里得)
- bzoj 1293: [SCOI2009]生日礼物 STL
- centos7 mysql数据库安装和配置
- QT qt5使用qdebug()输出中文 乱码
- 检索框的实现
- 最全面的Java多线程用法解析
- 稀疏自编码