Submission #1078466

#TimeUsernameProblemLanguageResultExecution timeMemory
1078466alexddSwapping Cities (APIO20_swap)C++17
0 / 100
2074 ms509136 KiB
#include "swap.h" #include <bits/stdc++.h> using namespace std; const int BUC = 900; //const int CNTB = 400; const int MAXN = 100000; struct str_DSU { int father[MAXN+5],siz[MAXN+5],cap1[MAXN+5],cap2[MAXN+5],islant[MAXN+5]; vector<pair<int*,int>> history; void init(int N) { for(int i=0;i<N;i++) { siz[i]=1; father[i]=cap1[i]=cap2[i]=i; islant[i]=1; } } int gas(int x) { if(father[x]==x) return x; return gas(father[x]); } void unite(int x, int y) { int rootx = gas(x); int rooty = gas(y); if(rootx==rooty) { if(islant[rootx]) { history.push_back({&islant[rootx],islant[rootx]}); islant[rootx]=0; } return; } if(siz[rootx] < siz[rooty]) { swap(rootx,rooty); swap(x,y); } history.push_back({&father[y],father[y]}); history.push_back({&siz[x],siz[x]}); father[y]=x; siz[x]+=siz[y]; if(!islant[rootx] || !islant[rooty]) { if(islant[rootx]) { history.push_back({&islant[rootx],islant[rootx]}); islant[rootx]=0; } } else if(x==cap1[rootx] && y==cap1[rooty]) { history.push_back({&cap1[rootx],cap1[rootx]}); cap1[rootx] = cap2[rooty]; } else if(x==cap1[rootx] && y==cap2[rooty]) { history.push_back({&cap1[rootx],cap1[rootx]}); cap1[rootx] = cap1[rooty]; } else if(x==cap2[rootx] && y==cap1[rooty]) { history.push_back({&cap2[rootx],cap2[rootx]}); cap2[rootx] = cap2[rooty]; } else if(x==cap2[rootx] && y==cap2[rooty]) { history.push_back({&cap2[rootx],cap2[rootx]}); cap2[rootx] = cap1[rooty]; } else { history.push_back({&islant[rootx],islant[rootx]}); islant[rootx]=0; } } void rollback(int t) { while((int)history.size() > t) { *history.back().first = history.back().second; history.pop_back(); } } }; vector<str_DSU> saves; vector<int> pozs; str_DSU dsu; void do_save(int i, int N) { //cout<<i<<" save\n"; pozs.push_back(i); saves.push_back(dsu); } vector<pair<int,pair<int,int>>> edges; void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) { for(int i=0;i<M;i++) edges.push_back({W[i],{U[i],V[i]}}); sort(edges.begin(),edges.end()); dsu.init(N); do_save(-1,N); for(int i=0;i<M;i++) { dsu.unite(edges[i].second.first, edges[i].second.second); if((i+1)%BUC==0 || i==M-1) { do_save(i,N); } } } int getMinimumFuelCapacity(int X, int Y) { int ults=0; for(int i=1;i<saves.size();i++) { if(saves[i].gas(X)==saves[i].gas(Y) && saves[i].islant[saves[i].gas(X)]==0) break; ults=i; } if(ults==(int)saves.size()-1) return -1; //str_DSU cop = saves[ults];///------------------------- int t = saves[ults].history.size(); for(int i=pozs[ults]+1;i<edges.size();i++) { int a = edges[i].second.first, b = edges[i].second.second; //cout<<a<<" "<<b<<" baga\n"; saves[ults].unite(a, b); if(saves[ults].gas(X)==saves[ults].gas(Y) && saves[ults].islant[saves[ults].gas(X)]==0) { saves[ults].rollback(t); //saves[ults] = cop;///-------------------------- return edges[i].first; break; } } assert(1==0); }

Compilation message (stderr)

swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:125:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<str_DSU>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |     for(int i=1;i<saves.size();i++)
      |                 ~^~~~~~~~~~~~~
swap.cpp:135:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  135 |     for(int i=pozs[ults]+1;i<edges.size();i++)
      |                            ~^~~~~~~~~~~~~
#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...