Submission #999211

# Submission time Handle Problem Language Result Execution time Memory
999211 2024-06-15T08:11:15 Z pan Connecting Supertrees (IOI20_supertrees) C++17
0 / 100
1 ms 348 KB
#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) 
	{
		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;
	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

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:71: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]
   71 |   for (ll i=0; i<q.size(); ++i)
      |                ~^~~~~~~~~
supertrees.cpp:80: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]
   80 |    for (ll i=0; i<q.size()-1; ++i) ret[q[i]][q[i+1]] = ret[q[i+1]][q[i]] = 1;
      |                 ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB b[0][0] is not 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -