标签:blog os io for ar 2014 log amp sp
给出每个点的父节点,存下来。
再从r2开始,dfs到r1,把这条路径上的所有结点的父节点改变方向就可以了。
#include <iostream> #include <cstdlib> #include <cstring> #include <string> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <map> #define inf 0x3f3f3f3f #pragma comment(linker, "/STACK:16777216") #define eps 1e-6 #define ll long long using namespace std; int f[50010],r1,r2; void dfs(int a,int last) { if(a==r1) { f[a]=last; return ; } dfs(f[a],a); f[a]=last; } int main() { int n,i; while(~scanf("%d%d%d",&n,&r1,&r2)) { for(i=1;i<=n;i++) { if(i==r1) { f[i]=r1; continue; } scanf("%d",&f[i]); } dfs(r2,r2); int flag=0; for(i=1;i<=n;i++) { if(i==r2) continue; if(flag) putchar(' '); else flag=1; printf("%d",f[i]); } puts(""); } return 0; }
标签:blog os io for ar 2014 log amp sp
原文地址:http://blog.csdn.net/u011032846/article/details/38826871