QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#778491#9713. Kill the treesurenjamts#WA 121ms32732kbC++201.9kb2024-11-24 14:53:312024-11-24 14:53:31

Judging History

你现在查看的是最新测评结果

  • [2024-11-24 14:53:31]
  • 评测
  • 测评结果:WA
  • 用时:121ms
  • 内存:32732kb
  • [2024-11-24 14:53:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define S second
#define F first
int n;
vector<vector<int>> adj;
vector<int> sz;
vector<vector<int>> heavy;
void findsz(int v, int last){
    for(auto u : adj[v]){
        if(u == last) continue;
        findsz(u, v);
        sz[v] += sz[u];
    }
}


void dfs(int v, int last, vector<int> &path){
      path.push_back(v);
      int hund = -1;
      for(auto u : adj[v]){
           if(u == last) continue;
           if(sz[u] * 2 >= sz[v]) hund = u;
      }
      if(hund == -1){
          heavy.push_back(path);
      }
      for(auto u : adj[v]){
          if(u == last) continue;
          if(u == hund){
                dfs(u, v, path);
          } else {
                vector<int> nw;
                dfs(u, v, nw);
          }
      }
}

void init(){
	 cin >> n;
	 int u, v;
	 adj.assign(n + 1, vector<int>());
	 sz.assign(n + 1, 1);
	 for(int i = 0; i < n - 1; i++){
         cin >> u >> v;
         adj[u].pb(v);
         adj[v].pb(u);
	 }
	 findsz(1, 1);
	 vector<int> initv;
     dfs(1, 1, initv);
}
int32_t main(){
     ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
     init();
     vector<int> ans[n + 5];
     for(auto &path : heavy){
          for(int i = 0; i < path.size(); i++){
               int l = i, r = path.size();
               int N = sz[path[i]];
               while(l + 1 < r){
                   int mid = (l + r)/2;
                   if(sz[path[mid]] * 2 >= N) l = mid;
                   else r = mid;
               }
               if(sz[path[l]] * 2 == N) ans[path[i]].push_back(path[l - 1]);
               ans[path[i]].push_back(path[l]);
          }
     }


     for(int i = 1; i <= n; i++){
          for(auto hariu : ans[i]) cout << hariu << " ";
          cout << '\n';
     }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 121ms
memory: 32732kb

input:

200000
42924 18271
60536 154257
107175 95680
196335 71607
158051 155259
110869 30974
143595 43516
4228 138046
26249 183847
123888 199873
15009 25362
166527 175160
15257 67159
124779 199363
148904 54047
5988 18123
58281 40739
44562 143880
72819 132492
137782 29662
130741 78276
55073 93292
82700 18328...

output:

1 134385 
45886 143670 
106649 126220 
44121 108393 
5226 95313 
147311 116080 
141180 
147983 
74120 7428 
161963 
3879 
178499 
171549 162544 
144413 
127262 
133093 188325 
171802 
43558 
28179 
140604 125217 
186651 
45633 176397 
26425 
3745 26982 
30063 
128965 
19661 148036 
141733 
115691 
3...

result:

wrong answer 11th numbers differ - expected: '116080', found: '147311'