Submission #416846

#TimeUsernameProblemLanguageResultExecution timeMemory
416846ismoilovVillage (BOI20_village)C++14
0 / 100
5 ms5016 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define all(x) (x).begin(), (x).end() #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++) #define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++) #define fm(a,i,c) for(int (a) = (i); (a) > (c); (a)--) #define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--) #define maxx 100010 set <int> g[maxx]; bool vis[maxx]; int amn[maxx]; void S() { int n, ans = 0; cin >> n; fp(i,1,n){ int x, y; cin >> x >> y; x --, y --; g[x].insert(y); g[y].insert(x); amn[i] = i; } // cout << endl; fp(x,0,n){ if(g[x].size() == 1 && vis[x] == 0){ int y; for(int it : g[x]) y = it; g[y].erase(x); g[x].erase(y); vis[x] = 1, vis[y] = 1; swap(amn[x], amn[y]); ans += 2; //cout << x << " " << y << "first\n"; } } bool ok = 1; while(ok){ ok = 0; fp(x,0,n){ if(vis[x] == 0){ set <int> d = g[x]; for(int y : d){ if(vis[y] == 1){ g[x].erase(y); g[y].erase(x); continue; } g[y].erase(x); g[x].erase(y); ans += 2; vis[y] = 1, vis[x] = 1; swap(amn[x], amn[y]); ok = 1; // cout << x << " " << y << "\n"; } } /* if(g[x].size() == 1){ int y; for(int it : g[x]) y = it; g[y].erase(x); g[x].erase(y); vis[x] = 1, vis[y] = 1; swap(amn[x], amn[y]); ok = 1; ans += 2; cout << x << " "; }*/ } } cout << ans << "\n"; fp(i,0,n) cout << amn[i]+1 << " "; } int main() { IOS; S(); }

Compilation message (stderr)

Village.cpp: In function 'void S()':
Village.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
Village.cpp:18:2: note: in expansion of macro 'fp'
   18 |  fp(i,1,n){
      |  ^~
Village.cpp:6:27: warning: unnecessary parentheses in declaration of 'x' [-Wparentheses]
    6 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
Village.cpp:27:2: note: in expansion of macro 'fp'
   27 |  fp(x,0,n){
      |  ^~
Village.cpp:6:27: warning: unnecessary parentheses in declaration of 'x' [-Wparentheses]
    6 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
Village.cpp:44:3: note: in expansion of macro 'fp'
   44 |   fp(x,0,n){
      |   ^~
Village.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
Village.cpp:78:2: note: in expansion of macro 'fp'
   78 |  fp(i,0,n)
      |  ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...