Submission #534634

#TimeUsernameProblemLanguageResultExecution timeMemory
534634shrimbCarnival (CEOI14_carnival)C++17
0 / 100
34 ms464 KiB
#include"bits/stdc++.h" #define int long long // #define endl '\n' using namespace std; int dsu[20001]; int ans[20001]; int Find (int x) { return dsu[x] == x ? x : dsu[x] = Find(dsu[x]); } void Union (int a, int b) { dsu[Find(a)] = Find(b); } int asked[151][151]; bool Query (int a, int b) { if (asked[a][b] != -1) return asked[a][b]; cout << "2 " << a << " " << b << endl; int x; cin >> x; return asked[a][b] = asked[b][a] = x == 1; } bitset<151> vis; signed main () { srand(time(0)); memset(asked, -1, sizeof asked); int n; cin >> n; for (int i = 1 ; i <= n ; i++) dsu[i] = i; for (int i = 1 ; i <= n ; i++) { vis = 0; vis[i] = 1; for (int j = 0 ; j < 23 ; j++) { int x = rand() % n + 1; if (vis[x]) {j-=(vis.count() < n); continue;} else { vis[x] = 1; if (Query(i, x)) Union(i, x); } } } int c = 1; for (int i = 1 ; i <= n ; i++) if (dsu[i] == i) ans[i] = c++; cout << 0 << " "; for (int i = 1 ; i <= n ; i++) cout << ans[Find(i)] << " "; cout << endl; }

Compilation message (stderr)

carnival.cpp: In function 'bool Query(long long int, long long int)':
carnival.cpp:23:21: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   23 |  return asked[a][b] = asked[b][a] = x == 1;
      |         ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
carnival.cpp: In function 'int main()':
carnival.cpp:39:33: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   39 |    if (vis[x]) {j-=(vis.count() < n); continue;}
      |                     ~~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...