Submission #873769

#TimeUsernameProblemLanguageResultExecution timeMemory
873769VictorNaboj (COCI22_naboj)C++17
40 / 110
1027 ms74044 KiB
// #pragma GCC target ("avx,avx2,fma") // #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast // #pragma GCC optimize ("unroll-loops") #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (ll i = (a); i < (b); ++i) #define per(i, a, b) for (ll i = (b) - 1; i >= (a); --i) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() #define sz(x) (ll)x.size() #define pb push_back #define debug(x) cout<<#x<<" = "<<x<<endl #define umap unordered_map #define uset unordered_set typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef long long ll; typedef pair<ll,ll> pll; typedef pair<ll,pll> ppll; typedef vector<ll> vll; typedef vector<pll> vpll; typedef vector<vll> vvll; const ll INF = 1'000'000'007; ll n,m; vector<umap<ll,ll>> graph; vector<ll> value; vector<pll> order; int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cin>>n>>m; graph.resize(n); rep(i,0,m) { ll u,v; cin>>u>>v; --u; --v; graph[u].emplace(v,1); graph[v].emplace(u,0); } value.assign(n,0); queue<ll> q; rep(u,0,n) { trav(edge,graph[u]) value[u]+=edge.second; if(value[u]%sz(graph[u])==0) q.push(u); } vector<bool> vis; vis.assign(n,0); while(!q.empty()) { ll u=q.front(); q.pop(); if(vis[u]) continue; vis[u]=1; if(sz(graph[u])) order.emplace_back(u,value[u]/sz(graph[u])); else order.emplace_back(u,0); trav(edge,graph[u]) { ll v,w; tie(v,w)=edge; graph[v].erase({u}); value[v]-=1-w; if(sz(graph[v])==0||value[v]%sz(graph[v])==0) q.push(v); } } if(sz(order)!=n) cout<<-1<<endl; else { cout<<n<<endl; reverse(all(order)); trav(item,order) cout<<item.first+1<<' '<<item.second<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...