Submission #122608

#TimeUsernameProblemLanguageResultExecution timeMemory
122608dualityMeetings (JOI19_meetings)C++14
100 / 100
1008 ms960 KiB
#define DEBUG 0 #include <bits/stdc++.h> using namespace std; #if DEBUG // basic debugging macros int __i__,__j__; #define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl #define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl #define printVar(n) cout<<#n<<": "<<n<<endl #define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl #define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;} #define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;} // advanced debugging class // debug 1,2,'A',"test"; class _Debug { public: template<typename T> _Debug& operator,(T val) { cout << val << endl; return *this; } }; #define debug _Debug(), #else #define printLine(l) #define printLine2(l,c) #define printVar(n) #define printArr(a,l) #define print2dArr(a,r,c) #define print2dArr2(a,r,c,l) #define debug #endif // define #define MAX_VAL 999999999 #define MAX_VAL_2 999999999999999999LL #define EPS 1e-6 #define mp make_pair #define pb push_back // typedef typedef unsigned int UI; typedef long long int LLI; typedef unsigned long long int ULLI; typedef unsigned short int US; typedef pair<int,int> pii; typedef pair<LLI,LLI> plli; typedef vector<int> vi; typedef vector<LLI> vlli; typedef vector<pii> vpii; typedef vector<plli> vplli; // ---------- END OF TEMPLATE ---------- #include "meetings.h" vi adjList[2000]; int done[2000],visited[2000],size[2000]; int doDFS(int u,int p) { int i; size[u] = 1; for (i = 0; i < adjList[u].size(); i++) { int v = adjList[u][i]; if ((v != p) && !visited[v]) size[u] += doDFS(v,u); } return size[u]; } int centroid(int u) { int i; int p = -1,r = u; doDFS(u,-1); while (1) { int h = -1; for (i = 0; i < adjList[u].size(); i++) { int v = adjList[u][i]; if ((v != p) && !visited[v] && ((h == -1) || (size[v] > size[h]))) h = v; } if (((h == -1) || (size[h] <= (size[r]/2))) && ((size[r]-size[u]) <= (size[r]/2))) break; else p = u,u = h; } return u; } int add(int u,int s) { int i; doDFS(s,-1); s = centroid(s); doDFS(s,-1); vpii sub; for (i = 0; i < adjList[s].size(); i++) { int t = adjList[s][i]; if (!visited[t]) sub.pb(mp(size[t],t)); } visited[s] = 1; if (sub.size() & 1) sub.pb(mp(0,s)); sort(sub.begin(),sub.end(),greater<pii>()); for (i = 0; i < sub.size(); i += 2) { int v = Query(sub[i].second,sub[i+1].second,u); if ((v == sub[i].second) || ((v == sub[i+1].second) && (sub[i+1].second != s))) { add(u,v); return 0; } else if (v != s) { int t = (Query(sub[i].second,s,u) == v) ? sub[i].second:sub[i+1].second; adjList[s].erase(find(adjList[s].begin(),adjList[s].end(),t)); adjList[t].erase(find(adjList[t].begin(),adjList[t].end(),s)); adjList[t].pb(v),adjList[v].pb(s); adjList[s].pb(v),adjList[v].pb(t); if (u != v) adjList[u].pb(v),adjList[v].pb(u); done[v] = 1; return 0; } } adjList[u].pb(s),adjList[s].pb(u); return 0; } void Solve(int N) { int i,j; done[0] = 1; for (i = 1; i < N; i++) { if (!done[i]) { fill(visited,visited+N,0); add(i,0),done[i] = 1; } } for (i = 0; i < N; i++) { for (j = 0; j < adjList[i].size(); j++) { if (adjList[i][j] < i) Bridge(adjList[i][j],i); } } }

Compilation message (stderr)

meetings.cpp: In function 'int doDFS(int, int)':
meetings.cpp:64:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < adjList[u].size(); i++) {
                 ~~^~~~~~~~~~~~~~~~~~~
meetings.cpp: In function 'int centroid(int)':
meetings.cpp:76:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0; i < adjList[u].size(); i++) {
                     ~~^~~~~~~~~~~~~~~~~~~
meetings.cpp: In function 'int add(int, int)':
meetings.cpp:91:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < adjList[s].size(); i++) {
                 ~~^~~~~~~~~~~~~~~~~~~
meetings.cpp:98:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < sub.size(); i += 2) {
                 ~~^~~~~~~~~~~~
meetings.cpp: In function 'void Solve(int)':
meetings.cpp:128:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < adjList[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...