Advertisement
ec1117

Untitled

Oct 22nd, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. 1394B
  2.  
  3. int n,m,k,ans;
  4. vpi adj[MX];
  5. map<pi,int> bad[MX];
  6.  
  7. int BAD[500][500];
  8. int hsh(pi p) { return 10*p.f+p.s; }
  9.  
  10. vpi st;
  11. void dfs(int x) {
  12.     if (x == k+1) {
  13.         ans ++;
  14.         return;
  15.     }
  16.     F0R(i,x) {
  17.         pi p = {x,i};
  18.         st.pb(p);
  19.         bool oops = 0;
  20.         trav(t,st) if (BAD[hsh(p)][hsh(t)]) oops = 1;
  21.         if (!oops) {
  22.             dfs(x+1);
  23.         }
  24.         st.pop_back();
  25.     }
  26. }
  27.  
  28. int main() {
  29.     setIO(); re(n,m,k);
  30.     F0R(i,m) {
  31.         int u,v,w; re(u,v,w);
  32.         adj[u].pb({w,v});
  33.     }
  34.     FOR(i,1,n+1) {
  35.         sort(all(adj[i]));
  36.         F0R(j,sz(adj[i])) bad[adj[i][j].s][{sz(adj[i]),j}] ++;
  37.     }
  38.     FOR(i,1,n+1) {
  39.         trav(a,bad[i]) trav(b,bad[i]) if (a.f != b.f) {
  40.             BAD[hsh(a.f)][hsh(b.f)] = 1;
  41.         } else if (a.s > 1) {
  42.             BAD[hsh(a.f)][hsh(b.f)] = 1;
  43.         }
  44.     }
  45.     dfs(1);
  46.     ps(ans);
  47.     // you should actually read the stuff at the bottom
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement