注:刘轩宇是抄的我的


struct group_info *groups_alloc(int gidsetsize){struct group_info *group_info;int nblocks;int i;nblocks = (gidsetsize + NGROUPS_PER_BLOCK - 1) / NGROUPS_PER_BLOCK;/* Make sure we always allocate at least one indirect block pointer */nblocks = nblocks ? : 1;group_info = kmalloc(sizeof(*group_info) + nblocks*sizeof(gid_t *), GFP_USER);if (!group_info)return NULL;group_info->ngroups = gidsetsize;group_info->nblocks = nblocks;atomic_set(&group_info->usage, 1);if (gidsetsize <= NGROUPS_SMALL)group_info->blocks[0] = group_info->small_block;else {for (i = 0; i < nblocks; i++) {gid_t *b;b = (void *)__get_free_page(GFP_USER);if (!b)goto out_undo_partial_alloc;group_info->blocks[i] = b;}}return group_info;out_undo_partial_alloc:while (--i >= 0) {free_page((unsigned long)group_info->blocks[i]);}kfree(group_info);return NULL;}EXPORT_SYMBOL(groups_alloc);void groups_free(struct group_info *group_info){if (group_info->blocks[0] != group_info->small_block) {int i;for (i = 0; i < group_info->nblocks; i++)free_page((unsigned long)group_info->blocks[i]);}kfree(group_info);}EXPORT_SYMBOL(groups_free);/* export the group_info to a user-space array */static int groups_to_user(gid_t __user *grouplist,const struct group_info *group_info){int i;unsigned int count = group_info->ngroups;for (i = 0; i < group_info->nblocks; i++) {unsigned int cp_count = min(NGROUPS_PER_BLOCK, count);unsigned int len = cp_count * sizeof(*grouplist);if (copy_to_user(grouplist, group_info->blocks[i], len))return -EFAULT;grouplist += NGROUPS_PER_BLOCK;count -= cp_count;}return 0;}/* fill a group_info from a user-space array - it must be allocated already */static int groups_from_user(struct group_info *group_info,gid_t __user *grouplist){int i;unsigned int count = group_info->ngroups;for (i = 0; i < group_info->nblocks; i++) {unsigned int cp_count = min(NGROUPS_PER_BLOCK, count);unsigned int len = cp_count * sizeof(*grouplist);if (copy_from_user(group_info->blocks[i], grouplist, len))return -EFAULT;grouplist += NGROUPS_PER_BLOCK;count -= cp_count;}return 0;}/* a simple Shell sort */static void groups_sort(struct group_info *group_info){int base, max, stride;int gidsetsize = group_info->ngroups;for (stride = 1; stride < gidsetsize; stride = 3 * stride + 1); /* nothing */stride /= 3;while (stride) {max = gidsetsize - stride;for (base = 0; base < max; base++) {int left = base;int right = left + stride;gid_t tmp = GROUP_AT(group_info, right);while (left >= 0 && GROUP_AT(group_info, left) > tmp) {GROUP_AT(group_info, right) =GROUP_AT(group_info, left);right = left;left -= stride;}GROUP_AT(group_info, right) = tmp;}stride /= 3;}}/* a simple bsearch */int groups_search(const struct group_info *group_info, gid_t grp){unsigned int left, right;if (!group_info)return 0;left = 0;right = group_info->ngroups;while (left < right) {unsigned int mid = left + (right - left)/2;if (grp > GROUP_AT(group_info, mid))left = mid + 1;else if (grp < GROUP_AT(group_info, mid))right = mid;elsereturn 1;}return 0;}/*** set_groups - Change a group subscription in a set of credentials* @new: The newly prepared set of credentials to alter* @group_info: The group list to install** Validate a group subscription and, if valid, insert it into a set* of credentials.*/int set_groups(struct cred *new, struct group_info *group_info){put_group_info(new->group_info);groups_sort(group_info);get_group_info(group_info);new->group_info = group_info;return 0;}EXPORT_SYMBOL(set_groups);/*** set_current_groups - Change current's group subscription* @group_info: The group list to impose** Validate a group subscription and, if valid, impose it upon current's task* security record.*/int set_current_groups(struct group_info *group_info){struct cred *new;int ret;new = prepare_creds();if (!new)return -ENOMEM;ret = set_groups(new, group_info);if (ret < 0) {abort_creds(new);return ret;}return commit_creds(new);}EXPORT_SYMBOL(set_current_groups);SYSCALL_DEFINE2(getgroups, int, gidsetsize, gid_t __user *, grouplist){const struct cred *cred = current_cred();int i;if (gidsetsize < 0)return -EINVAL;/* no need to grab task_lock here; it cannot change */i = cred->group_info->ngroups;if (gidsetsize) {if (i > gidsetsize) {i = -EINVAL;goto out;}if (groups_to_user(grouplist, cred->group_info)) {i = -EFAULT;goto out;}}out:return i;}/**   SMP: Our groups are copy-on-write. We can set them safely*  without another task interfering.*/SYSCALL_DEFINE2(setgroups, int, gidsetsize, gid_t __user *, grouplist){struct group_info *group_info;int retval;if (!nsown_capable(CAP_SETGID))return -EPERM;if ((unsigned)gidsetsize > NGROUPS_MAX)return -EINVAL;group_info = groups_alloc(gidsetsize);if (!group_info)return -ENOMEM;retval = groups_from_user(group_info, grouplist);if (retval) {put_group_info(group_info);return retval;}retval = set_current_groups(group_info);put_group_info(group_info);return retval;}/** Check whether we're fsgid/egid or in the supplemental group..*/int in_group_p(gid_t grp){const struct cred *cred = current_cred();int retval = 1;if (grp != cred->fsgid)retval = groups_search(cred->group_info, grp);return retval;}EXPORT_SYMBOL(in_group_p);int in_egroup_p(gid_t grp){const struct cred *cred = current_cred();int retval = 1;if (grp != cred->egid)retval = groups_search(cred->group_info, grp);return retval;}
|#include<bits/stdc++.h>
using namespace std;const int N = 100010, M = 400010;int n, m;
int h[N], e[M],w[M], ne[M], idx;
int dist[N];
int q[N];
void add(int a, int b, int c){e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++;
}
// 求1号点到n号点的最短路:边权为1
// 返回值为最短路,含义是:从1号点到n号点使用的边权小于等于mid 的条数
//如果 返回值 == 6,说明从1号点到n号点,使用边权小于等于mid的边的条数为6条
int bfs(int mid){memset(dist, 0x3f, sizeof dist);dist[1] = 0;int hh = 0, tt = 0;q[0] = 1;while( hh <= tt){int t = q[hh ++];for(int i = h[t]; ~i; i = ne[i]){if(w[i] > mid)  continue;int j = e[i];if(dist[j] > dist[t] + 1){dist[j] = dist[t] + 1;q[++tt] = j;}}}return dist[n];
}int main(){cin >> n >> m;memset(h, -1, sizeof h);while(m --){int a, b, c;cin >> a >> b >> c;add(a, b, c), add(b, a, c);}// 二分,枚举合适的最优边权int l = 0, r = 1e6;while(l < r){int mid = l + r >> 1;if(bfs(mid) <= n) r = mid;else l = mid + 1;}//输出二分出来的分界点,二分退出时l == rcout << r << endl;
}

hackertyper相关推荐

  1. 如何使用Swift Playgrounds制作东西

    by Harshita Arora 通过Harshita Arora 如何使用Swift Playgrounds制作东西 (How to make something with Swift Playg ...

  2. 装逼神器,逼真黑客范儿

    新博客地址 我们平时看美国大片,经常看到黑客或者情报部门人员以熟练的指法敲击键盘,屏幕上面代码跳动,窃取信息或者进行某些入侵控制操作,大家都会感觉特别崇拜剧中的人物.我们也常常会梦想将来能够拥有剧中人 ...

  3. 上班假装很忙,下班装逼唬妹子的几个神器,人人都能用

    我还是先一本正经的声明一下,上班时间应该认真工作,这几个工具仅供娱乐. 老板从远处走来,似乎向你的位置走了过来,是来催工作的! 可你一直在摸鱼,工作根本没开始.怎么办? 1. 第一招:甩锅给电脑 1. ...

  4. 100 Most Brilliant Tech Hacks You Need To Know Right Now

    原来我发在115社区,现在搬运过来. http://115.com/22500407/post/edit?tid=74122 100 Most Brilliant Tech Hacks You Nee ...

  5. 开发者必看 | DevWeekly 第1期:什么是时间复杂度?

    hello,大家好,我是 Jackpop,硕士毕业于哈尔滨工业大学,曾在华为.阿里等大厂工作,如果你对升学.就业.技术提升等有疑惑,不妨交个朋友: 我是Jackpop,我们交个朋友吧! DevWeek ...

  6. 发两个可以装逼的网址

    1.https://cybermap.kaspersky.com/ 2.http://map.norsecorp.com/#/ --------------------------更新 http:// ...

  7. 几款黑客Geek装逼神器,打开乱按键盘就行

    我们常常会在一些好莱坞电影大片里看到超级黑客高手,在电脑前轻松"黑"进别人的安全系统的场景.那纯熟自如地输入一大堆复杂的代码,不一下子就入侵/破解完成,是不是很羡慕? 其实咱们也可 ...

  8. 推荐几个学习黑客技术的合法网站,学不会别来打我[doge]

    前两天发了一篇关于通过游戏学习编程的几个网站的文章,(地址在这https://blog.csdn.net/weixin_51273415/article/details/121022536 ,没看的小 ...

  9. 有趣的装B利器-快速打出代码

    之前在晚上看到一个网页比较有趣,只要出发键盘按钮即可自动打出写好的代码,大家可以在给MM修电脑或者远程修电脑时最后即将完成的时候传个文件,这么写来装一装,哈哈!我把它写成Winform程序,添加一个w ...

最新文章

  1. linux内核SMP负载均衡浅析
  2. Java中的static关键字详解
  3. 使用Aspect和Spring Profile进行电子邮件过滤
  4. 远程管理口怎么看地址_红烧羊肉怎么样做才能滋味浓郁,咸甜适口,且回味有奶香?看这里...
  5. 时间格式化需要注意点不可使用本地时间
  6. 对象交互 空调与摇控器 0107
  7. 浏览网页时,手机显示手机被恶意攻击,不停震动,一直弹出应用要我下载,有没有问题?
  8. 服务器芯片组思维导图,服务器思维导图
  9. 对抗生成网络(Generative Adversarial Network, GAN)
  10. V4 乱码问题总结 v5 也可以参考
  11. kktv电视剧鸿蒙,KKTV K70系列新品上市 京东、天猫、苏宁易购同步预售
  12. 阿里云kafka安装
  13. 《星际争霸》怀念星际历史上最强的队伍系列二
  14. tensorflow实现对图片的读取(tf.image.decode_jepg和tf.image.decode_png)
  15. Centos7修改时区、时间
  16. 具名元组namedtuple
  17. byval 和byref的区别,今天刚明白。
  18. 徐州地区地理生物计算机考试试题,2020年初中学业水平考试 地理、生物7月14日开考...
  19. 牛客小白月赛24 J—建设道路
  20. mac java串口驱动,使用CH340/341的模块在Mac上驱动安装

热门文章

  1. SpringBoot整合Swagger
  2. 省市县三级联动 javascript 原生实现实例
  3. WIN7下搭建CORDOVA环境
  4. siki学院愤怒的小鸟脚本
  5. matlab 离散控制系统仿真,基于Matlab的离散控制系统仿真.doc
  6. spring之spring security
  7. it Ebook 免费
  8. RSTP P/A机制分析
  9. 手机变速齿轮_变速齿轮手机版下载-变速齿轮 安卓版v1.0-PC6安卓网
  10. 正点原子STM32(基于HAL库)0