传送门
题目描述

分析
李巨给的题
这题其实就是个模拟,但是题目这个表述就很迷
给你的
n
n
n个点不一定都在同一条链上,所以最后打印出来的答案不一定有
n
n
n行
另外注意用
m
a
p
map
map存储信息内存会爆炸,所以用数组存就可以了
代码
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define debug(x) cout<<#x<<":"<<x<<endl;
#define dl(x) printf("%lld\n",x);
#define di(x) printf("%d\n",x);
#define _CRT_SECURE_NO_WARNINGS
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
const int INF = 0x3f3f3f3f;
const int N = 2e6 + 10;
const ll mod= 1000000007;
const double eps = 1e-9;
const double PI = acos(-1);
template<typename T>inline void read(T &a){char c=getchar();T x=0,f=1;while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=(x<<1)+(x<<3)+c-'0';c=getchar();}a=f*x;}
int gcd(int a,int b){return (b>0)?gcd(b,a%b):a;}
int ne[N],fa[N];
int a[N];
int main(){
int fi,ed;
int n;
cin >> fi >> n;
for(int i = 1;i <= n;i++){
int x,y;
int p;
cin >> x >> p >> y;
a[x] = p;
ne[x] = y;
fa[y] = x;
}
ed = fi;
while(ne[ed] != -1){
ed = ne[ed];
}
while(1){
if(ed == fi){
printf("%05d %d -1\n",ed,a[ed]);
break;
}
printf("%05d %d %05d\n",ed,a[ed],fi);
ed = fa[ed];
if(ed == fi){
printf("%05d %d -1\n",fi,a[fi]);
break;
}
printf("%05d %d %05d\n",fi,a[fi],ed);
fi = ne[fi];
}
}
/**
* ┏┓ ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃ ┃
* ┃ ━ ┃ ++ + + +
* ████━████+
* ◥██◤ ◥██◤ +
* ┃ ┻ ┃
* ┃ ┃ + +
* ┗━┓ ┏━┛
* ┃ ┃ + + + +Code is far away from
* ┃ ┃ + bug with the animal protecting
* ┃ ┗━━━┓ 神兽保佑,代码无bug
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛ + + + +
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛+ + + +
*/
该博客主要探讨了一个模拟链路分析的问题,通过给定的起点和一系列节点信息,实现链路的遍历和输出。代码中使用了邻接表来存储图结构,并避免了使用map导致的内存消耗。通过不断更新起点和终点,最终形成完整的链路表示。
296

被折叠的 条评论
为什么被折叠?



