Task: | Distances |
Sender: | wabadaba |
Submission time: | 2021-01-31 19:42:12 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | RUNTIME ERROR | 0 |
#2 | RUNTIME ERROR | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | RUNTIME ERROR | 0.01 s | 1, 2 | details |
#2 | WRONG ANSWER | 0.01 s | 2 | details |
Compiler report
In file included from /usr/include/c++/7/cassert:44:0, from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33, from input/code.cpp:1: input/code.cpp: In function 'void solve()': input/code.cpp:157:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] assert(ans.size() <= n); ~~~~~~~~~~~^~~~
Code
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef double db; typedef string str; // change ld to db if neccesary typedef pair<int,int> pi; typedef pair<ll,ll> pl; typedef pair<ld,ld> pld; typedef set<int> si; typedef set<ll> sl; typedef set<ld> sld; typedef set<str> ss; typedef set<pi> spi; typedef set<pl> spl; typedef set<pld> spld; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<ld> vld; typedef vector<str> vs; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<si> vsi; typedef vector<sl> vsl; typedef vector<pld> vpld; #define mp make_pair #define f first #define s second #define sz(x) (int)(x).size() #define all(x) begin(x), end(x) #define rall(x) (x).rbegin(), (x).rend() #define rsz resize #define ins insert #define ft front() #define bk back() #define pf push_front #define pb push_back #define eb emplace_back #define lb lower_bound #define ub upper_bound #define forr(i,a,b) for (int i = (a); i < (b); i++) #define ford(i,a,b) for (int i = (a)-1; i >= (b); i--) #define trav(a,x) for (auto& a: x) template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } int pct(int x) { return __builtin_popcount(x); } int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x)) int fstTrue(function<bool(int)> f, int lo, int hi) { hi ++; assert(lo <= hi); // assuming f is increasing while (lo < hi) { // find first index such that f is true int mid = (lo+hi)/2; f(mid) ? hi = mid : lo = mid+1; } return lo; } const ll MOD = 1e9+7; const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[8] = {0, 1, 0, -1, -1, 1, -1, 1}; int gcd(int a,int b){return b?gcd(b,a%b):a;} ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;} ll modInv(ll a){return binpow(a, MOD-2);} bool sortcol(const vl& v1, const vl& v2) {return v1[1] < v2[1];} bool sortpair(const pi& p1, const pi& p2) {return p1.f < p2.f;} mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<long long unsigned> distribution(0,10); void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} // void __print(mi x) {cerr << x;} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define dbg(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define dbg(x...) #endif const int mxN = 2e5+5; int n, par[105]; si adj[105]; bool vis[105]; vi ans; void dfs(int x = 0, int p = -1) { par[x] = p; if (x) adj[x].erase(p); trav(i,adj[x]) if (i != p) dfs(i,x); } void solve() { cin >> n; forr(i,0,n-1) { int a, b; cin >> a >> b; a--, b--; adj[a].ins(b); adj[b].ins(a); } dfs(); int num = 1, pos = 0; ans.pb(0); vis[0] = 1; while (num < n) { // vis[pos] = 1; // num++; // ans.pb(pos); if (!adj[pos].size()) { forr(i,0,3) { pos = par[pos]; if (pos == -1) break; if (adj[pos].size() >= 2) { adj[pos].erase(adj[pos].begin()); forr(j,i+1,3) if (adj[pos].size()) pos = *adj[pos].begin(); vis[pos] = 1; num++; ans.pb(pos); break; } else if (!vis[pos]) { vis[pos] = 1; num++; ans.pb(pos); } } } else { forr(i,0,3) if (adj[pos].size()) pos = *adj[pos].begin(); // dbg(pos); vis[pos] = 1; num++; ans.pb(pos); } } assert(ans.size() <= n); trav(i,ans) cout << i+1 << " "; cout << "\n"; fill(par,par+105,0), fill(vis,vis+105,0); forr(i,0,105) adj[i].clear(); ans.clear(); } int main() { cin.tie(0)->sync_with_stdio(0); // freopen(".in", "r", stdin); // freopen(".out", "w", stdout); int tc = 1; cin >> tc; while (tc--) solve(); }
Test details
Test 1
Group: 1, 2
Verdict: RUNTIME ERROR
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 |
---|
(empty) |
Error:
code: input/code.cpp:157: void solve(): Assertion `ans.size() <= n' failed.
Test 2
Group: 2
Verdict: WRONG ANSWER
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 60 12 11 47 93 19 47 47 47 4... Truncated |