Codeforces Round #203 (Div. 2)B
来源:互联网 发布:source linux命令 编辑:程序博客网 时间:2024/05/18 00:06
看了半天没看懂什么意思。。。
题意:求一条最长的路,终点是旅馆,要求路上的联通杜小于等于2
下面是代码:
#include<iostream>#include<vector>#include<cstring>using namespace std;const int MAX_N=100100;int N;int degree[MAX_N],to[MAX_N],hotel[MAX_N];void solve(){ int ans=0,pre; vector<int> path,ans1; for(int i=1;i<=N;i++) { if(hotel[i]) { path.clear(); path.push_back(i); pre=to[i]; while(pre&°ree[pre]<=2) { path.push_back(pre); pre=to[pre]; } //if(degree[pre]<=2) // path.push_back(pre); } if(path.size()>ans) { ans=path.size(); ans1=path; } } cout<<ans<<endl; cout<<ans1[ans1.size()-1]; for(int i=ans1.size()-2;i>=0;i--) cout<<' '<<ans1[i]; cout<<endl;}int main(){ while(cin>>N) { memset(degree,0,sizeof(degree)); memset(to,0,sizeof(to)); for(int i=1;i<=N;i++) cin>>hotel[i]; for(int i=1;i<=N;i++) { cin>>to[i]; degree[i]++; degree[to[i]]++; } solve(); } return 0;}
- Codeforces Round #203 (Div. 2) B. Resort
- Codeforces Round #203 (Div. 2)B
- Codeforces Round #203(Div. 2)B. Resort
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #134 (Div. 2)B. Airport
- Codeforces Round #170 (Div. 2) problem B
- Codeforces Round #173 (Div. 2) Problem B
- Codeforces Round #181 (Div. 2) B. Coach
- Codeforces Round #185 (Div. 2)--A,B
- Codeforces Round #171 (Div. 2) B
- Codeforces Round #169 (Div. 2) B题
- Codeforces Round #188 (Div. 2) B题
- Codeforces Round #192 (Div. 2) B
- Codeforces Round #206 (Div. 2) - b
- Codeforces Round #202 (Div. 2)B-贪心
- Codeforces Round #206 (Div. 2)B
- Codeforces Round #209 (Div. 2) B. Permutation
- Codeforces Round #122 (Div. 2) B. Square
- 算法:回溯算法
- Oracle DB 使用资源管理
- arch linux root 自动登录
- 分享Unity3d的消息机制实现
- 快速排序
- Codeforces Round #203 (Div. 2)B
- windows7 x64位内python3.3.2下导入模块xlwt3 v0.1.2出错解决方法
- 了解iOS中XML解析
- java界面编程把界面放在屏幕中央的方法
- Oracle之sql标准之连接查询汇总
- 客户需求与设计的差距
- 大学生的精神生活
- 你有觉得自己很傻么?
- postgreSQL 启用远程访问