|
| 1 | +/* |\ | | ||\ \ /(_~ |~)|_~|\/||_~|\/||~)|_~|~) |
| 2 | + |~\|_|/\||~\ | ,_) |~\|__| ||__| ||_)|__|~\ |
| 3 | +
|
| 4 | + \ //~\| | |\ |~)|_~ | ||\ ||/~\| ||_~ |
| 5 | + | \_/\_/ |~\|~\|__ \_/| \||\_X\_/|__ |
| 6 | + (J U S T L I K E E V E R Y O N E E L S E !) |
| 7 | +
|
| 8 | + __ ,..---.._ |
| 9 | + +''''`--''-..`--..__ |
| 10 | + .\ _,/:i--._`:-:+._`.``-._ |
| 11 | + /`.._,,' \ `-.``--:.b....=. |
| 12 | + |`..__,,..`. '`.__::i--.-::_ |
| 13 | + )- .....--i'\.. --+`'''-' |
| 14 | + ,' .'.._,.-'|._-b\ |
| 15 | + /,'<' V `oi| \ _. |
| 16 | + |/ -|,--.." ,'-. ||\.. _.,;:'_<' |
| 17 | + ''/ | . ' |\||'\ /-'_/' `. |
| 18 | + |,','| , . .-.|:.`. + .,:.. | |
| 19 | + ._,:'/ /-\ '^' -Y"\ |.| || /,+8d| | |
| 20 | + .|/,'| |/':: ':=:' ,'| | | \|| "+)=' | |
| 21 | + |+,';' /|_/ \ _/ \b':.\ \'| .|| ,' |
| 22 | + ,,:-i''_i' | ``-.Y',. ,|`: | \;- | |_,' |
| 23 | + __ |'| |i:'._ ,' ,' ,; | |-)-' __--:b__ |
| 24 | + .P| | |/,'|\ - ._ / / _,Y- ,:/' `. `'".._ |
| 25 | + ,'|| -','' | ._i._ `':| ,..,' ,Y;' \ `- ._ |
| 26 | + |||||,.. | \ '-.._ _,' / _,b-' `. '-. |
| 27 | + ||||P..i, .| '....,-' _,'''''-''' ' _,.. `\ |
| 28 | + +'` <'/ |`-.....---' ._ ,._ |
| 29 | + | | ,'``,:-''''/,--`. |
| 30 | + Y|.b_,,: | || ,;,Y' / |. |
| 31 | + ,' /'----' .'| .. | | '" .`Y' .,-b_....;;,. |
| 32 | + |+|,' | | \., ' ,' `:. _ ,/__` _=: _,'``- |
| 33 | + / +,' | /\_........:.' '"----:::::'Y .'.| ||| |
| 34 | + |' ' .'/- \ /'|| || | ||| |
| 35 | + ||| /| \L /'|| ||/ | ||| |
| 36 | + `.| ,'/ .| / ,'||/o;/ ||| |
| 37 | + `..._,, | |/| ' ||| |
| 38 | + ``-' | |, ||| |
| 39 | + | ,. | ||| |
| 40 | + ,=--------.... | "" | ||| |
| 41 | +,/,'. i=..+._ ,.. '..;---:::''- | | |
| 42 | +'/| __....b `-''`---....../.,Y'''''j:.,.._ | `._ |
| 43 | +.' _.Y.-' `.. ii:,'--------' | :-+. .| | b\ |
| 44 | +| .=_,.---'''''--...:..--:' / _..-----..:= | | '|\ |
| 45 | +| '-''`'--- ---'_,,,--'' `,.. | | \. |
| 46 | + \ . ,' _,--'' :dg: _,/ ||| | \ |
| 47 | +`::b\` _,-i,-' ,..---' ,|:| | _| |
| 48 | +`'--.:-._ ____,,,;.,'' `--._ '''''''' |'|' .' ' |
| 49 | + ``'--....Y''-' `''--..._..____._____...,' | 'o-' |
| 50 | + `''''`'''i==_+=_=i__ |
| 51 | + ||'''- ' `. |
| 52 | + `-.......-'' |
| 53 | +*/ |
| 54 | +#include<bits/stdc++.h> |
| 55 | +using namespace std; |
| 56 | + |
| 57 | +#define fastio ios_base::sync_with_stdio(0); cin.tie(0) |
| 58 | +#define LL long long |
| 59 | +#define FOR(i, j, k) for (int i=j ; i<k ; i++) |
| 60 | +#define ROF(i, j, k) for (int i=j ; i>=k ; i--) |
| 61 | + |
| 62 | +const long long INF = 1e18; |
| 63 | +const long long MAX = 1e5+10; |
| 64 | +const LL mod = 1000*1000*1000 +7; |
| 65 | +vector<int>adj[MAX]; |
| 66 | +vector<int>d(MAX,0); |
| 67 | +vector<int>f(MAX); |
| 68 | +vector<int>e; |
| 69 | +vector<int>seg; |
| 70 | +void dfs(int u, int p){ |
| 71 | + d[u] = d[p] + 1; |
| 72 | + f[u] = e.size(); |
| 73 | + e.push_back(u); |
| 74 | + for(auto v : adj[u]){ |
| 75 | + if(v!=p) dfs(v,u); |
| 76 | + e.push_back(u); |
| 77 | + } |
| 78 | +} |
| 79 | +void build(int i, int l , int r){ |
| 80 | + if(l==r){ |
| 81 | + seg[i] = e[l]; |
| 82 | + return; |
| 83 | + } |
| 84 | + int m = l + (r-l)/2; |
| 85 | + build(2*i,l,m); |
| 86 | + build(2*i+1,m+1,r); |
| 87 | + seg[i] = d[2*i] < d[2*i+1] ? 2*i : 2*i+1; |
| 88 | +} |
| 89 | + |
| 90 | +int query(int l, int r, int b, int e, int i){ |
| 91 | + if(b>r || e<l) return -1; |
| 92 | + if(b>=l && e <= r) return seg[i]; |
| 93 | + int m = (b+e)/2; |
| 94 | + int L = query(l,r,b,m,2*i); |
| 95 | + int R = query(l,r,m+1,e,2*i+1); |
| 96 | + if(L==-1) return R; |
| 97 | + if(R==-1) return L; |
| 98 | + return d[L]<=d[R]?L:R; |
| 99 | +} |
| 100 | +void dfs1(int u, int p, int c){ |
| 101 | + d[u] = c; |
| 102 | + for(auto v : adj[u]){ |
| 103 | + if(v!=p) dfs1(v,u,1-c); |
| 104 | + } |
| 105 | +} |
| 106 | +int main(){ |
| 107 | + fastio; |
| 108 | + int t=1;// cin>>t; |
| 109 | + while(t--){ |
| 110 | + int n,q; cin>>n>>q; |
| 111 | + FOR(i,1,n){ |
| 112 | + int x,y; cin>>x>>y; |
| 113 | + adj[x].push_back(y); |
| 114 | + adj[y].push_back(x); |
| 115 | + } |
| 116 | + // dfs(1,0); |
| 117 | + // seg.resize(MAX*100); |
| 118 | + // build(1,0,e.size()-1); |
| 119 | + // FOR(i,0,q){ |
| 120 | + // int x,y; cin>>x>>y; |
| 121 | + // int lca = query(min(f[x],f[y]),max(f[x],f[y]),0,e.size()-1,1); |
| 122 | + // int dis = d[x]-d[lca] + d[y]-d[lca] + 1; |
| 123 | + // if(dis&1) cout<<"Town\n"; |
| 124 | + // else cout<<"Road\n"; |
| 125 | + // } |
| 126 | + dfs1(1,0,0); |
| 127 | + FOR(i,0,q){ |
| 128 | + int x,y; cin>>x>>y; |
| 129 | + if(d[x]==d[y]) cout<<"Town\n"; |
| 130 | + else cout<<"Road\n"; |
| 131 | + } |
| 132 | + } |
| 133 | +} |
0 commit comments