Task: | Distances |
Sender: | lolok123 |
Submission time: | 2021-01-31 11:37:43 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 29 |
#2 | ACCEPTED | 71 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2 | details |
#2 | ACCEPTED | 0.01 s | 2 | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:49:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for(int i=0; i<ans.size(); ++i){ ~^~~~~~~~~~~
Code
#define MOD 1000000007 #include <bits/stdc++.h> #include <numeric> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; void dfill(vector<vector<int>> &adj,vector<pair<int,vector<int>>> &adjr,int root,int parent=-1){ adjr[root].first=parent; for(auto &i:adj[root]){ if(i==parent) continue; adjr[root].second.push_back(i); dfill(adj,adjr,i,root); } } void edfs(vector<pair<int,vector<int>>>&,vector<int>&,int); void sdfs(vector<pair<int,vector<int>>> &adj,vector<int> &ans,int root){ ans.push_back(root); for(auto &i:adj[root].second){ edfs(adj,ans,i); } } void edfs(vector<pair<int,vector<int>>> &adj,vector<int> &ans,int root){ for(auto &i:adj[root].second){ sdfs(adj,ans,i); } ans.push_back(root); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int T; cin>>T; for(int T_Case=1;T_Case<=T;++T_Case){ int n; vector<int> ans; cin>>n; vector<vector<int>> adj(n); vector<pair<int,vector<int>>> adjr(n); for(int i=0; i<n-1; ++i){ int u,v; cin>>u>>v; adj[--u].push_back(--v); adj[v].push_back(u); } dfill(adj,adjr,0); edfs(adjr,ans,0); for(int i=0; i<ans.size(); ++i){ cout<<ans[i]+1<<' '; } cout<<'\n'; } }
Test details
Test 1
Group: 1, 2
Verdict: ACCEPTED
input |
---|
100 8 5 2 2 3 3 7 ... |
correct output |
---|
1 8 2 5 6 7 3 4 1 7 2 8 3 6 4 5 1 4 6 2 7 5 8 3 1 8 3 2 4 7 6 5 1 6 4 7 5 2 3 8 ... |
user output |
---|
4 3 5 6 2 7 8 1 3 8 2 7 5 6 4 1 4 3 8 7 2 5 6 1 6 3 8 2 4 7 5 1 6 8 3 2 5 7 4 1 ... Truncated |
Test 2
Group: 2
Verdict: ACCEPTED
input |
---|
100 100 37 59 81 37 44 81 ... |
correct output |
---|
1 99 82 81 59 5 71 55 17 24 13... |
user output |
---|
22 60 44 37 17 5 55 71 59 24 3... Truncated |