#include "incursion.h"
#include <bits/stdc++.h>
using namespace std;
//#define int long long
//#define ld long double
#define show(x,y) cerr << y << " " << #x << endl;
#define show2(x,y,i,j) cerr << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cerr << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cerr << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef pair<pii,int>pi2;
int n;
vector<int>adj[45005];
int pp[45005];
int sz[45005];
void dfs(int index, int par){
sz[index]=1;
for(auto it:adj[index]){
if(it==par) continue;
pp[it]=index;
dfs(it,index);
sz[index]+=sz[it];
}
}
vector<int>mark(vector<pair<int, int>> F, int safe){
n=F.size()+1;
for(int x=0;x<n-1;x++){
adj[F[x].first].push_back(F[x].second);
adj[F[x].second].push_back(F[x].first);
}
int rt=0;
for(int x=1;x<=n;x++){
if(adj[x].size()==2){
dfs(x,-1);
rt=x;
break;
}
}
//show(rt,rt);
vector<int>ans(n,0);
int cur=safe;
int take=-1;
while(cur){
ans[cur-1]=1;
if(take==-1){
ans[cur-1]=1;
if(cur==rt) break;
take=cur;
cur=pp[cur];
}
else{
//show2(cur,cur,take,take);
int nxt=sz[cur]-sz[take]-1;
//show2(sz[take],sz[take],nxt,nxt);
if(sz[take]<nxt){
ans[cur-1]=1;
}
else ans[cur-1]=2;
if(cur==rt) break;
take=cur;
cur=pp[cur];
}
}
return ans;
}
//visit()
void locate(vector<pair<int, int>> F, int curr, int t){
n=F.size()+1;
for(int x=0;x<=n;x++){
adj[x].clear();
}
for(int x=0;x<n-1;x++){
adj[F[x].first].push_back(F[x].second);
adj[F[x].second].push_back(F[x].first);
}
memset(pp,0,sizeof(pp));
memset(sz,0,sizeof(sz));
for(int x=1;x<=n;x++){
if(adj[x].size()==2){
dfs(x,-1);
break;
}
}
bool done[n+5];
memset(done,0,sizeof(done));
while(1){
//show2(curr,curr,t,t);
done[curr]=true;
if(t==0){
//go up
done[curr]=true;
t=visit(pp[curr]);
curr=pp[curr];
}
else if(t==1){
//go small
bool amos=false;
pii mini={1e9,0};
for(auto it:adj[curr]){
if(it==pp[curr]) continue;
if(done[it]) continue;
//show(it,it);
mini=min(mini,{sz[it],it});
amos=true;
}
//show2(mini.first,mini.first,mini.second,mini.second);
if(!amos||done[mini.second]) return;
t=visit(mini.second);
curr=mini.second;
}
else{
//go big
pii maxi={-1e9,0};
bool amos=false;
for(auto it:adj[curr]){
if(it==pp[curr]) continue;
if(done[it]) continue;
maxi=max(maxi,{sz[it],it});
amos=true;
}
if(!amos||done[maxi.second]) return;
t=visit(maxi.second);
curr=maxi.second;
}
//show(curr,curr);
}
}
Compilation message
interface.cpp: In function 'int main()':
interface.cpp:44:55: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
44 | if(fread(T.data(), sizeof(int), 2 * N - 2, stdin) != 2 * N - 2) exit(0);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
interface.cpp:50:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
50 | int l = (numbers.size() == N ? N : 0);
| ~~~~~~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
2 ms |
3076 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
105 ms |
12428 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
64 ms |
8056 KB |
Partially correct |
2 |
Partially correct |
78 ms |
8076 KB |
Partially correct |
3 |
Partially correct |
89 ms |
8060 KB |
Partially correct |
4 |
Partially correct |
86 ms |
11524 KB |
Partially correct |
5 |
Partially correct |
129 ms |
11412 KB |
Partially correct |
6 |
Partially correct |
164 ms |
11616 KB |
Partially correct |
7 |
Partially correct |
74 ms |
8060 KB |
Partially correct |
8 |
Partially correct |
82 ms |
7840 KB |
Partially correct |
9 |
Partially correct |
81 ms |
7796 KB |
Partially correct |
10 |
Partially correct |
73 ms |
7796 KB |
Partially correct |
11 |
Partially correct |
78 ms |
7812 KB |
Partially correct |
12 |
Partially correct |
73 ms |
8092 KB |
Partially correct |
13 |
Partially correct |
73 ms |
7840 KB |
Partially correct |
14 |
Partially correct |
62 ms |
6696 KB |
Partially correct |
15 |
Partially correct |
57 ms |
6708 KB |
Partially correct |
16 |
Partially correct |
74 ms |
7688 KB |
Partially correct |
17 |
Partially correct |
80 ms |
7776 KB |
Partially correct |
18 |
Partially correct |
79 ms |
7748 KB |
Partially correct |
19 |
Partially correct |
75 ms |
7800 KB |
Partially correct |
20 |
Partially correct |
54 ms |
6436 KB |
Partially correct |
21 |
Partially correct |
64 ms |
6604 KB |
Partially correct |
22 |
Partially correct |
52 ms |
6828 KB |
Partially correct |
23 |
Partially correct |
56 ms |
6704 KB |
Partially correct |
24 |
Partially correct |
59 ms |
6684 KB |
Partially correct |
25 |
Partially correct |
59 ms |
6936 KB |
Partially correct |
26 |
Partially correct |
78 ms |
7764 KB |
Partially correct |
27 |
Partially correct |
77 ms |
7808 KB |
Partially correct |
28 |
Partially correct |
76 ms |
7808 KB |
Partially correct |
29 |
Partially correct |
71 ms |
7796 KB |
Partially correct |
30 |
Partially correct |
74 ms |
7772 KB |
Partially correct |
31 |
Partially correct |
83 ms |
7804 KB |
Partially correct |
32 |
Partially correct |
79 ms |
7812 KB |
Partially correct |
33 |
Partially correct |
77 ms |
7844 KB |
Partially correct |
34 |
Partially correct |
75 ms |
7844 KB |
Partially correct |
35 |
Partially correct |
75 ms |
8060 KB |
Partially correct |
36 |
Partially correct |
76 ms |
7816 KB |
Partially correct |
37 |
Partially correct |
81 ms |
7772 KB |
Partially correct |
38 |
Partially correct |
73 ms |
7836 KB |
Partially correct |
39 |
Partially correct |
73 ms |
7776 KB |
Partially correct |
40 |
Partially correct |
76 ms |
7808 KB |
Partially correct |
41 |
Partially correct |
77 ms |
7764 KB |
Partially correct |
42 |
Partially correct |
70 ms |
7784 KB |
Partially correct |
43 |
Partially correct |
77 ms |
7820 KB |
Partially correct |
44 |
Partially correct |
81 ms |
7820 KB |
Partially correct |
45 |
Partially correct |
74 ms |
8096 KB |
Partially correct |
46 |
Partially correct |
71 ms |
7784 KB |
Partially correct |
47 |
Partially correct |
70 ms |
8016 KB |
Partially correct |
48 |
Partially correct |
77 ms |
7796 KB |
Partially correct |
49 |
Partially correct |
76 ms |
7796 KB |
Partially correct |
50 |
Partially correct |
79 ms |
7916 KB |
Partially correct |
51 |
Partially correct |
83 ms |
7808 KB |
Partially correct |
52 |
Partially correct |
75 ms |
7836 KB |
Partially correct |
53 |
Partially correct |
71 ms |
7752 KB |
Partially correct |
54 |
Partially correct |
82 ms |
7684 KB |
Partially correct |
55 |
Partially correct |
76 ms |
7840 KB |
Partially correct |
56 |
Partially correct |
80 ms |
8096 KB |
Partially correct |
57 |
Partially correct |
78 ms |
7964 KB |
Partially correct |
58 |
Partially correct |
72 ms |
8064 KB |
Partially correct |
59 |
Correct |
88 ms |
8052 KB |
Correct |
60 |
Correct |
73 ms |
7840 KB |
Correct |
61 |
Correct |
75 ms |
7836 KB |
Correct |
62 |
Correct |
83 ms |
8044 KB |
Correct |
63 |
Correct |
81 ms |
8060 KB |
Correct |
64 |
Correct |
75 ms |
8060 KB |
Correct |
65 |
Correct |
71 ms |
7836 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
2 ms |
3076 KB |
Partially correct |
2 |
Incorrect |
105 ms |
12428 KB |
Not correct |
3 |
Halted |
0 ms |
0 KB |
- |