Submission #1027013

#TimeUsernameProblemLanguageResultExecution timeMemory
1027013HD1Connecting Supertrees (IOI20_supertrees)C++14
11 / 100
156 ms48972 KiB
#include "supertrees.h" #include<bits/stdc++.h> #define all(x) x.begin(),x.end() #define sz(x) ll(x.size()) #define pb push_back using namespace std; typedef long long ll; typedef pair<ll,ll> ii; const ll MAX=1e6; int f[MAX]; vector<int> adj[MAX]; set<ll> s; int fiend(int u){ if(f[u] == u)return u; return f[u]=fiend(f[u]); } void unir(int u,int v){ int x=fiend(u); int y=fiend(v); if(x!=y){ f[x]=y;//x en y } return; } int construct(vector<vector<int>> p) { int n = p.size(); for(int i=0; i<n; i++){ f[i]=i; } for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ if(p[i][j]==1){ unir(i,j); } } } vector<vector<int>> gfo(n,vector<int>(n)); for(int i=0; i<n; i++){ fiend(f[i]); fiend(i); adj[f[i]].pb(i);// aqui estan cada subarbol de 1 o mas s.insert(f[i]); } for(int i=0; i<n; i++){//armamos subarboles if(sz(adj[i])){ for(int j=0; j+1<sz(adj[i]); j++){ gfo[adj[i][j]][adj[i][j+1]]=1; gfo[adj[i][j+1]][adj[i][j]]=1; } } } for(auto it:s){//representante de cada grupo for(int i=0; i<n; i++){//par ver si tiene un 2 if(it==f[i])continue; if(p[it][i]==2){ gfo[it][f[i]]=1; gfo[f[i]][it]=1; } } } build(gfo); return 1; } /* con fe 9 0 2 2 2 2 2 2 2 2 2 0 1 1 1 2 2 2 2 2 1 0 1 1 2 2 2 2 2 1 1 0 1 2 2 2 2 2 1 1 1 0 2 2 2 2 2 2 2 2 2 0 1 1 1 2 2 2 2 2 1 0 1 1 2 2 2 2 2 1 1 0 1 2 2 2 2 2 1 1 1 0 */
#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...