Submission #410343

#TimeUsernameProblemLanguageResultExecution timeMemory
410343nathanlee726Meetings (JOI19_meetings)C++14
100 / 100
1020 ms1060 KiB
//#include<i_am_noob_orz> #include<bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define ll long long //#define int ll #define ull unsigned long long #define pii pair<int,int> #define X first #define Y second #define mod ((ll)1e9+7) #define pb push_back #define mp make_pair #define abs(x) ((x)>0?(x):(-(x))) #define F(n) Fi(i,n) #define Fi(i,n) Fl(i,0,n) #define Fl(i,l,n) for(int i=l;i<n;i++) #define memres(a) memset(a,0,sizeof(a)) #define all(a) a.begin(),a.end() #define sz(a) ((int)a.size()) #define ceiling(a,b) (((a)+(b)-1)/(b)) #define endl '\n' #define bit_count(x) __builtin_popcountll((x)) #define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define jimmy_is_kind false typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree; //#define LOCAL #ifdef LOCAL #define bug(...) cerr<<"#"<<__LINE__<<' '<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__) template<typename T> void _do(T && x) {cerr<<x<<endl;} template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr<<x<<", "; _do(y...);} #define IOS() int Query(int x,int y,int z){return x;} void Bridge(int u,int v){cout<<u<<" "<<v<<endl;} #else #include<meetings.h> #define IOS() ios_base::sync_with_stdio(0), cin.tie(0) #define endl '\n' #define bug(...) #endif int add(int a,int b){return(a+b>=mod?a+b-mod:a+b);} int sub(int a,int b){return(a<b?a+mod-b:a-b);} int po(int a,int b){ if(b==0)return 1; if(b==1)return(a%mod); int tem=po(a,b/2); if(b&1)return(((tem*tem)%mod)*a)%mod; else return(tem*tem)%mod; } int GCD(int a,int b){ int x=0; int ra,rb; while(a&&b){ if(((a&1)==0)&&((b&1)==0)){ a>>=1,b>>=1,x++; } else if((a^b)&1){ if(a&1)b>>=1; else a>>=1; } else{ ra=abs(a-b),rb=min(a,b); a=ra,b=rb; } } return max(a,b)<<x; } int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);} set<int> g[2005]; bool used[2005],vis[2005]; int pa[2005]; pii dfs(int v,int f){ pa[v]=f; int re0=v,re1=0; for(int u:g[v]){ if(u==f||vis[u])continue; pii re=dfs(u,v); if(re.Y>re1)re0=re.X,re1=re.Y; } return {re0,re1+1}; } void Solve(int n){ int x=Query(0,1,2); if(x>=0&&x<=2){ F(3){ if(i==x)continue; g[i].insert(x); g[x].insert(i); } } else{ F(3){ g[i].insert(x); g[x].insert(i); } } memres(used); F(3)used[i]=1; used[x]=1; Fl(i,3,n){ if(used[i])continue; memres(vis); pii tmp=dfs(0,-1); int p1=tmp.X; tmp=dfs(p1,-1); int p2=tmp.X; int re; if(p1!=p2)re=Query(p1,p2,i); else re=p1; while(1){ if(re==p1||re==p2){ used[i]=1; g[re].insert(i); g[i].insert(re); break; } if(used[re]){ int tp2=p2; while(tp2!=-1){ vis[tp2]=1; tp2=pa[tp2]; } vis[re]=0; tmp=dfs(re,-1); p1=tmp.X; tmp=dfs(p1,-1); p2=tmp.X; if(p1!=p2)re=Query(p1,p2,i); else re=p1; } else{ int tp2=p2; vector<int> v; while(tp2!=-1){ v.pb(tp2); tp2=pa[tp2]; } int l=0,r=sz(v)-1; while(l+1<r){ int mi=(l+r)/2; int t1=Query(v[l],v[mi],i); if(t1!=v[mi])r=mi; else l=mi; } assert(l+1==r); p1=v[l],p2=v[r]; g[p1].erase(g[p1].find(p2)); g[p2].erase(g[p2].find(p1)); g[p1].insert(re); g[re].insert(p1); g[p2].insert(re); g[re].insert(p2); if(re!=i){ g[re].insert(i); g[i].insert(re); } used[i]=1; used[re]=1; break; } } } F(n){ for(int j:g[i]){ if(i<j)Bridge(i,j); } } } #ifdef LOCAL signed main(){ int n; cin>>n; Solve(n); return 0; } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...