Codeforces 29C Mail Stamps 【离散化 + DFS】
来源:互联网 发布:ubuntu好用的输入法 编辑:程序博客网 时间:2024/06/18 18:34
题目链接:Codeforces 29C Mail Stamps
题意:给你n条无向边,保证只存在两条路径可以遍历完所有的点。让你输出任意一条路径。
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>#include <vector>#include <queue>#include <map>#include <stack>#define PI acos(-1.0)#define CLR(a, b) memset(a, (b), sizeof(a))#define fi first#define se second#define ll o<<1#define rr o<<1|1using namespace std;typedef long long LL;typedef pair<int, int> pii;const int MAXN = 2*1e5+100;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;void getmax(int &a, int b) {a = max(a, b); }void getmin(int &a, int b) {a = min(a, b); }void add(LL &x, LL y) { x += y; x %= MOD; }int u[MAXN], v[MAXN];map<int, int> fp;vector<int> G[MAXN];bool vis[MAXN];int rec[MAXN];void DFS(int u){ for(int i = 0; i < G[u].size(); i++) { int v = G[u][i]; if(vis[v]) continue; cout << " " << rec[v]; vis[v] = true; DFS(v); }}int main(){ int n; cin >> n; int top = 0; fp.clear(); for(int i = 1; i <= n; i++) { scanf("%d%d", &u[i], &v[i]); rec[top++] = u[i]; rec[top++] = v[i]; fp[u[i]]++; fp[v[i]]++; } sort(rec, rec+top); int T = unique(rec, rec+top) - rec; //cout << T << endl; for(int i = 0; i < T; i++) { G[i].clear(); vis[i] = false; } for(int i = 1; i <= n; i++) { int sx = lower_bound(rec, rec+T, u[i]) - rec; int ex = lower_bound(rec, rec+T, v[i]) - rec; G[sx].push_back(ex); G[ex].push_back(sx); } int s; for(int i = 0; i < T; i++) { if(fp[rec[i]] == 1) { s = i; break; } } cout << rec[s]; vis[s] = true; DFS(s); return 0;}
0 0
- Codeforces 29C Mail Stamps 【离散化 + DFS】
- Codeforces 29C Mail Stamps【离散化+DFS】
- CF-29C - Mail Stamps(DFS+离散化)
- codeforces-29C-Mail Stamps【离散化】【STLmap】
- Codeforces 29C Mail Stamps(离散化 && map初探)
- codeforces 29C Mail Stamps(dfs)
- Codeforces 29C:Mail Stamps(STL的应用+DFS)
- Codeforces #29 C. Mail Stamps
- codeforces C. Mail Stamps
- 【codeforces】29C—Mail Stamps
- Codeforces Beta Round #29 (Div. 2, Codeforces format), problem: (C) Mail Stamps 图论
- CodeForcse 29C (DFS+离散化)
- Codeforces 844 C Sorting by Subsequences(离散+dfs+排序)
- cf29C. Mail Stamps
- Codeforces 138C(区间更新+离散化)
- CodeForces 670C Cinema(排序,离散化)
- Coconuts----DFS+离散化
- 165 - Stamps(dfs)
- Codeforces 400A Inna and Choose Options 【水题】
- 51nod1191 贪心+优先级队列
- Python version 3.4 required, which was not found in the registry
- Java工程师成神之路
- 抽象类和接口
- Codeforces 29C Mail Stamps 【离散化 + DFS】
- 10.C进阶之变量和常量
- Java 信号量 Semaphore 介绍
- 合并排序
- Infinite Sequence
- Spring使用util Schema
- POJ 3126 Prime Path 筛法+最短路
- Bellmanford 最短路(1)
- iOS UIAppearance使用详解