#include<bits/stdc++.h>
#ifndef NTFOrz
#include "stations.h"
#endif
clock_t __t=clock();
namespace my_std{
using namespace std;
#define pii pair<int,int>
#define fir first
#define sec second
#define MP make_pair
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define drep(i,x,y) for (int i=(x);i>=(y);i--)
#define go(x) for (int i=head[x];i;i=edge[i].nxt)
#define templ template<typename T>
#define sz 2333
typedef long long ll;
typedef double db;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
templ inline void read(T& t)
{
t=0;char f=0,ch=getchar();double d=0.1;
while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
t=(f?-t:t);
}
template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
char __sr[1<<21],__z[20];int __C=-1,__zz=0;
inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
inline void print(register int x)
{
if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
while(__z[++__zz]=x%10+48,x/=10);
while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
}
void file()
{
#ifdef NTFOrz
freopen("a.in","r",stdin);
#endif
}
inline void chktime()
{
#ifdef NTFOrz
cout<<(clock()-__t)/1000.0<<'\n';
#endif
}
#ifdef mod
ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
ll inv(ll x){return ksm(x,mod-2);}
#else
ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
#endif
// inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;
namespace Build
{
int n;
struct hh{int t,nxt;}edge[sz<<1];
int head[sz],ecnt;
void make_edge(int f,int t)
{
edge[++ecnt]=(hh){t,head[f]};
head[f]=ecnt;
edge[++ecnt]=(hh){f,head[t]};
head[t]=ecnt;
}
void clear(){rep(i,0,n-1) head[i]=0;ecnt=0;}
int id[sz],cc;
#define v edge[i].t
void dfs(int x,int fa,int p)
{
if (p) id[x]=++cc;
go(x) if (v!=fa) dfs(v,x,p^1);
if (!p) id[x]=++cc;
}
#undef v
vector<int> work()
{
cc=0;
dfs(0,-1,1);
vector<int>res; rep(i,0,n-1) res.push_back(id[i]);
return res;
}
}
vector<int> label(int n,int K,vector<int>u,vector<int>v)
{
Build::clear();
Build::n=n; rep(i,0,n-2) Build::make_edge(u[i],v[i]);
return Build::work();
}
int find_next_station(int s,int t,vector<int>V)
{
if (s<V[0])
{
if (t<s) return V.back();
rep(i,0,(int)V.size()-2) if (t<=V[i]) return V[i];
assert(0);
}
if (t>s) return V[0];
drep(i,(int)V.size()-1,1) if (t>=V[i]) return V[i];
assert(0);
}
#ifdef NTFOrz
//#include "stations.h"
#include <cstdio>
#include <cassert>
#include <map>
#include <vector>
#include <algorithm>
static int max_label = 0;
static int r, n, k, q;
static std::vector<int> u, v, labels, answers;
static std::map<int, int> reverse_labels;
static std::vector<std::vector<int>> adjlist;
static int s, t, w;
static std::vector<int> c;
int main() {file();
assert(scanf("%d", &r) == 1);
for (int tc = 0; tc < r; tc++) {
assert(scanf("%d%d", &n, &k) == 2);
u.resize(n - 1);
v.resize(n - 1);
adjlist.clear();
adjlist.resize(n);
for (int i = 0; i < n - 1; i++) {
assert(scanf("%d%d", &u[i], &v[i]) == 2);
adjlist[u[i]].push_back(v[i]);
adjlist[v[i]].push_back(u[i]);
}
labels = label(n, k, u, v);
if ((int)labels.size() != n) {
printf("Number of labels not equal to %d\n", n);
exit(0);
}
reverse_labels.clear();
for (int i = 0; i < n; i++) {
if (labels[i] < 0 || labels[i] > k) {
printf("Label not in range 0 to %d\n", k);
exit(0);
}
if (reverse_labels.find(labels[i]) != reverse_labels.end()) {
printf("Labels not unique\n");
exit(0);
}
reverse_labels[labels[i]] = i;
if (labels[i] > max_label) {
max_label = labels[i];
}
}
assert(scanf("%d", &q) == 1);
for (int i = 0; i < q; i++) {
assert(scanf("%d%d%d", &s, &t, &w) == 3);
c.clear();
for (int v : adjlist[s]) {
c.push_back(labels[v]);
}
std::sort(c.begin(), c.end());
int answer = find_next_station(labels[s], labels[t], c);
if (!std::binary_search(c.begin(), c.end(), answer)) {
printf("Label %d returned by find_next_station not found in c\n", answer);
exit(0);
}
answers.push_back(reverse_labels[answer]);
}
}
printf("%d\n", max_label);
for (int index : answers) {
printf("%d\n", index);
}
exit(0);
}
#endif
Compilation message
stations.cpp: In function 'void my_std::print(int)':
stations.cpp:36:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
36 | if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
| ^~
stations.cpp:36:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
36 | if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
| ^~
stations.cpp:38:3: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
38 | while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
| ^~~~~
stations.cpp:38:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
38 | while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
1016 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
1024 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
1024 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
1016 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
1024 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |