CSES - Datatähti Open 2021 - Results
Submission details
Task:Distances
Sender:rishb369
Submission time:2021-01-30 16:45:49 +0200
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#10.01 s1, 2details
#20.01 s2details

Compiler report

input/code.cpp: In function 'void usaco(std::__cxx11::string)':
input/code.cpp:12:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen((s+".in").c_str(), "r", stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input/code.cpp:13:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen((s+".out").c_str(), "w", stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Code

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;

void usaco(string s){
  freopen((s+".in").c_str(), "r", stdin);
  freopen((s+".out").c_str(), "w", stdout);
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
#ifdef LOCAL_DEFINE
	freopen("input.txt", "r", stdin);
#endif
  int t;
  cin >> t;
  while(t--){
    int n;
    cin >> n;
    vector<int> adj[n+2];
    for(int i = 0; i < n-1; i++){
      int a, b;
      cin >> a >> b;
      adj[a].push_back(b);
      adj[b].push_back(a);
    }
    queue<int> q;
    q.push(1);
    vector<int> vis(n+1, 0);
    while(!q.empty()){
      int a = q.front();
      //cerr << a << '\n';
      q.pop();
      if(vis[a]) continue;
      vis[a] = 1;
      cout << a << ' ';
      for(auto i: adj[a]){
      	if(!vis[i]){
	        q.push(i);
	      }
      }
    }
    cout << '\n';
  }
}

Test details

Test 1

Group: 1, 2

Verdict:

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
1 4 8 3 2 7 5 6 
1 3 5 7 6 4 8 2 
1 4 3 6 8 2 5 7 
1 6 5 8 2 4 7 3 
1 6 8 4 3 7 2 5 
...
Truncated

Test 2

Group: 2

Verdict:

input
100
100
37 59
81 37
44 81
...

correct output
1 99 82 81 59 5 71 55 17 24 13...

user output
1 22 45 99 30 60 82 44 19 81 6...
Truncated