BestCoder #1-2 HDU 4858
来源:互联网 发布:办公软件 编辑:程序博客网 时间:2024/05/23 00:01
暴力的方法能过,但是网上有更优化的方法,
#include <iostream>#include <string.h>#include <stdio.h>#include <algorithm>#include <vector>#include <map>#include <queue>using namespace std;#define LL long long#define N 100010#define mod 1000000007vector<int> V[N],up[N];//V记录边,up记录邻接节点,但度数自己大int in[N];//记录节点度数int sum[N],add[N];//add 保存更新int main(){ // priority_queue<int,vector<int>,greater<int> > int T; int n,m,Q; int a,b; int i,j; scanf("%d",&T); while(T--) { scanf("%d %d",&n,&m); for(i=1;i<=n;i++){ V[i].clear(); in[i]=0; up[i].clear(); sum[i]=add[i]=0; } while(m--) { scanf("%d %d",&a,&b); V[a].push_back(b); V[b].push_back(a); in[b]++; in[a]++; } for(a=1;a<=n;a++) for(j=0;j<V[a].size();j++) { b=V[a][j]; if(in[b]>=in[a]) up[a].push_back(b); } scanf("%d",&Q); int cmd,u,v; while(Q--) { scanf("%d %d",&cmd,&u); if(cmd==0) { scanf("%d",&v); add[u]+=v; for(i=0; i<up[u].size(); i++) { j=up[u][i]; sum[j]+=v; } } else { int ans=sum[u]; for(i=0; i<up[u].size(); i++) { j=up[u][i]; if(in[j]!=in[u]) ans+=add[j]; } printf("%d\n",ans); } } } return 0;}
0 0
- BestCoder #1-2 HDU 4858
- HDU 4883 TIANKENG’s restaurant Bestcoder 2-1(模拟)
- 【HDU】BestCoder Round #11 (Div. 2)
- hdu 5600 BestCoder Round #67 (div.2)
- hdu 5637 BestCoder Round #74 (div.2)
- hdu 5652 bestcoder 77 div2 2
- HDU 5718 oracle BestCoder 2nd Anniversary
- HDU BestCoder Round #1 1002 项目管理
- hdu Bestcoder # 1 逃生 拓扑排序
- hdu 5130 && BestCoder 1st Anniversary 1001
- BestCoder Round #52 (div.2)(hdu 5417,hdu 5418)
- BestCoder Round #79 (div.2) hdu 5660 ,hdu 5661
- HDU 5366 The mook jong——BestCoder Round #50(div.1 div.2)
- HDU 5365 Run ——BestCoder Round #50(div.1 div.2)
- HDU 5428 The Factor——BestCoder Round #54(div.1 div.2)
- HDU 5429 Geometric Progression(大数模板)——BestCoder Round #54(div.1 div.2)
- HDU 5495 LCS(其实就是找环)——BestCoder Round #58(div.1 div.2)
- HDU 5569 matrix(DP)——BestCoder Round #63(div.1 div.2)
- 矩阵十题【五】 VOJ1049 HDU 2371 Decode the Strings
- Minimum Inversion Number
- Minimum Inversion Number(HDU 1394)
- tip6:若不想使用编译器自动生成的函数,就该明确拒绝
- 【项目开发】 Discuz 头部和尾部模板修改
- BestCoder #1-2 HDU 4858
- Ubuntu 安装Chrome步骤
- effective java (12) 考虑实现Comparable接口
- 设计模式学习--Prototype
- Android View系统解析(下)
- 【项目开发】Discuz头部导航的代码
- LeetCode Search a 2D Matrix
- Maven 常用命令整理
- 中缀式变后缀式