FZU月赛20160416 ABEF
2016-04-21 22:03
375 查看
Problem A ABCDEFG
Accept: 302 Submit: 442
View Code
Accept: 302 Submit: 442
Time Limit: 1000 mSec Memory Limit : 32768 KB
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <cmath> #include <queue> #include <stack> #include <vector> #include <map> #include <set> using namespace std; const int INF = 0x3f3f3f3f; const int N = 1e5 + 10; int a , U , V ; int vis ; vector<int> g[N << 1]; int main() { // freopen("in", "r", stdin); int n; while(~scanf("%d", &n)) { memset(vis, 0, sizeof vis); for(int i = 0; i <= n; ++i) g[i].clear(); int tot = 0; for(int i = 0; i < n; ++i) { scanf("%d%d", &U[i], &V[i]); a[tot++] = U[i]; a[tot++] = V[i]; } sort(a, a + tot); tot = unique(a, a + tot) - a; for(int i = 0; i < n; ++i) { int u = lower_bound(a, a + tot, U[i]) - a, v = lower_bound(a, a + tot, V[i]) - a; g[u].push_back(v); g[v].push_back(u); } int x = -1, y = -1; for(int i = 0; i < tot; ++i) { if(g[i].size() == 1) { if(x == -1) x = i; else y = i; } } if(a[x] > a[y]) swap(x, y); printf("%d ", a[x]); vis[x] = 1; x = g[x][0]; for(int i = 0; i < n - 1; ++i) { printf("%d ", a[x]); vis[x] = 1; int u = g[x][0]; int v = g[x][1]; if(vis[u]) x = v; else x = u; } printf("%d\n", a[x]); } return 0; }
View Code
相关文章推荐
- 用matlab实现同一个序列重复N倍
- stm32定时器实现60秒定时秒表
- 如何用ModelsimSE仿真IP核-以PLL为例
- iOS 多线程
- 二、测试作业
- Python函数式编程——学习笔记
- 无权最短路径
- Backbone与Angular的比较
- 深入理解ThreadLocal
- Spark 基础 —— 元组(tuple)
- sql连接自读串
- 输出中文的解决方式
- M*N矩阵旋转
- Educational Codeforces Round 12 A. Buses Between Cities 水题
- 如何用ModelsimSE仿真IP核-以PLL为例
- 个人工作总结(3)
- 团队冲刺第二天
- iOS 多线程 浅述
- addin注册菜单命令名称冲突解决
- Java 类的一般特征