Submission #999234

#TimeUsernameProblemLanguageResultExecution timeMemory
999234panConnecting Supertrees (IOI20_supertrees)C++17
21 / 100
128 ms30036 KiB
#include <bits/stdc++.h> //#include "bits_stdc++.h" //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define endl '\n' #define f first #define s second #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define input(x) scanf("%lld", &x); #define input2(x, y) scanf("%lld%lld", &x, &y); #define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z); #define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a); #define print(x, y) printf("%lld%c", x, y); #define show(x) cerr << #x << " is " << x << endl; #define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl; #define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl; #define all(x) x.begin(), x.end() #define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end()); #define FOR(i, x, n) for (ll i =x; i<=n; ++i) #define RFOR(i, x, n) for (ll i =x; i>=n; --i) using namespace std; mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count()); //using namespace __gnu_pbds; //#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> //#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> typedef long long ll; typedef long double ld; typedef pair<ld, ll> pd; typedef pair<string, ll> psl; typedef pair<ll, ll> pi; typedef pair<pi, ll> pii; typedef pair<pi, pi> piii; ll par[1005]; ll find(ll x) {return ((par[x]==x)?x:par[x] = find(par[x]));} void unite(ll x, ll y){if ((x=find(x))!=(y=find(y))) par[x] = y;} vector<ll> compress; ll adj[1005][1005]; bool visited[1005]; void build(std::vector<std::vector<int> > b); int construct(std::vector<std::vector<int> > p) { ll n = p.size(); vector<vector<int> > ret(n, vector<int> (n, 0)); for (ll i=0; i<n; ++i) for (ll j=0; j<n; ++j) if (p[i][j]==3) return 0; for (ll i=0; i<n; ++i) par[i] = i; for (ll i=0; i<n; ++i) for (ll j=0; j<n; ++j) if (p[i][j]!=0) unite(i, j); for (ll i=0; i<n; ++i) for (ll j=0; j<n; ++j) if (find(i)==find(j) && p[i][j]==0) return 0; for (ll i=0; i<n; ++i) par[i] = i; for (ll i=0; i<n; ++i) for (ll j=0; j<n; ++j) if (p[i][j]==1) unite(i, j); for (ll i=0; i<n; ++i) for (ll j=0; j<n; ++j) if (find(i)==find(j) && p[i][j]!=1) return 0; compress.clear(); for (ll i=0; i<n; ++i) { //show2(i, find(i)); if (find(i)==i) compress.pb(i); else ret[i][find(i)] = ret[find(i)][i] = 1; } for (ll i=0; i<n; ++i) for (ll j=0; j<n; ++j) adj[i][j] = 0; for (ll i=0; i<n; ++i) for (ll j=0; j<n; ++j) if (p[i][j]==2) adj[find(i)][find(j)] = adj[find(j)][find(i)] = 1; for (ll i=0; i<n; ++i) par[i] = i; for (ll u: compress) for (ll u2: compress) {if (adj[u][u2]==1) unite(u, u2);} for (ll u: compress) for (ll u2: compress) if (u!=u2 && find(u)==find(u2) && adj[u][u2]!=1) return 0; fill(visited,visited+n, 0); for (ll u: compress) { if (visited[u]) continue; vector<ll> q; q.pb(u); for (ll i=0; i<q.size(); ++i) { ll now = q[i]; for (ll u: compress) if (!visited[u] && adj[now][u]) {visited[u] = 1; q.pb(u);} } if (q.size()==2) return 0; if (q.size()>1) { ret[q[0]][q.back()] = ret[q.back()][q[0]] = 1; for (ll i=0; i<q.size()-1; ++i) ret[q[i]][q[i+1]] = ret[q[i+1]][q[i]] = 1; } } build(ret); return 1; }

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:75:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |   for (ll i=0; i<q.size(); ++i)
      |                ~^~~~~~~~~
supertrees.cpp:84:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |    for (ll i=0; i<q.size()-1; ++i) ret[q[i]][q[i+1]] = ret[q[i+1]][q[i]] = 1;
      |                 ~^~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...