您的位置:首页 > 其它

FZU月赛20160416 ABEF

2016-04-21 22:03 375 查看
Problem A ABCDEFG

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: