boolgao(int m){ memset(d, 0, sizeof d); G.clear();G.resize(tot + 1); for (int i = 1; i <= m; ++i) { int u = getId(s[i][0]), v= getId(s[i][1]); G[u].push_back(v); ++d[v]; } queue<int>q; for (int i =1; i <= tot; ++i) { if (d[i]) continue; q.push(i); } int cnt = 0; while (!q.empty()) { int u = q.front(); q.pop(); ++cnt; for (auto &v : G[u]) { if (--d[v] == 0) { q.push(v); } } } return cnt != tot; }
int n;
voidRUN(){ while (cin >> n) { mp.clear(); tot = 0; for (int i = 1; i <= n; ++i){ cin >> s[i][0] >> s[i][1]; getId(s[i][0]); getId(s[i][1]); } bool F = true; for (int i = 1; i <= n; ++i) { if (gao(i)) { cout << s[i][0] << " " << s[i][1] << endl; F = false; break; } } if (F) cout << "0\n"; } }
#define endl "\n" using ll = longlong; using db = double; using pSI = pair<string, int>;
constint N = 2e5 + 10;
int vis[N], num[N], pos; string s, t;
boolf(conststring &str){ int len = str.size(); if (len == 1) { returnisdigit(str[0]); } if (str[0] == '0') returnfalse; for (auto &c : str) { if (!isdigit(c)) { returnfalse; } } returntrue; }
int len;
pSI get(){ pSI tmp = pSI("", -1); while (pos < len && t[pos] == ' ') ++pos; while (pos < len && t[pos] != ' ') { if (tmp.second == -1) tmp.second = vis[pos]; tmp.first += t[pos]; ++pos; } return tmp; }
voidRUN(){ s = t = ""; int pre = -1; int n = 0; while (getline(cin, s)) { ++n; if (!t.empty() && isdigit(t.end()[-1]) && isdigit(s[0])) { t += s; } else { t += " "; t += s; ++pre; } int length = t.size(); for (int i = pre + 1; i < length; ++i) vis[i] = n; pre = length - 1; } len = t.size(); pos = 0; vector<string> vec; while (true) { pSI tmp = get(); if (tmp.second == -1) break; if (f(tmp.first)) { ++num[tmp.second]; vec.push_back(tmp.first); } } for (int i = 0, sze = vec.size(); i < sze; ++i) { cout << vec[i] << " \n"[i == sze - 1]; } for (int i = 1; i <= n; ++i) { cout << num[i] << endl; } }
voidinsert(char *s){ int len = strlen(s); int now = root; for (int i = 0; i < len; ++i) { if (t[now].nx[s[i] - '0'] == -1) t[now].nx[s[i] - '0'] = newnode(); now = t[now].nx[s[i] - '0']; } ++t[now].cnt; }
voidbuild(){ queue<int> q; t[root].fail = root; for (int i = 0; i < 2; ++i) { if (t[root].nx[i] == -1) { t[root].nx[i] = root; } else { t[t[root].nx[i]].fail = root; q.push(t[root].nx[i]); } } while (!q.empty()) { int now = q.front(); q.pop(); for (int i = 0; i < 2; ++i) { if (t[now].nx[i] == -1) { t[now].nx[i] = t[t[now].fail].nx[i]; } else { t[t[now].nx[i]].fail = t[t[now].fail].nx[i]; q.push(t[now].nx[i]); } } } }
ll gao(){ for (int i = 0; i <= m; ++i) for (int j = 0; j <= tot; ++j) f[i][j] = 0; f[0][root] = 1; for (int i = 0; i < m; ++i) { for (int j = 1; j <= tot; ++j) { if (t[j].cnt > 0) continue; for (int k = 0; k < 2; ++k) { if (t[j].nx[k] != -1) { f[i + 1][t[j].nx[k]] += f[i][j]; continue; } } } } ll res = 1ll << m; for (int i = 1; i <= tot; ++i) { if (t[i].cnt) continue; res -= f[m][i]; } return res; } } acam;
LL gao(){ LL res1 = 0, res2 = 0; for (int i = 1; i <= n; ++i) { int cnt = 0; for (int j = 1; j <= n; ++j) { if (i == j) continue; qrr[++cnt] = p[j] - p[i]; } sort(qrr + 1, qrr + 1 + cnt); for (int j = 1; j <= cnt; ++j) { qrr[j + cnt] = qrr[j]; } sumx[0] = sumy[0] = 0; cnt <<= 1; for (int j = 1; j <= cnt; ++j) { sumx[j] = (sumx[j - 1] + qrr[j].x) % mod; sumy[j] = (sumy[j - 1] + qrr[j].y) % mod; } int q = 1, s = 1, t = 1; for (int j = 1; j < n; ++j) { q = max(q, j); Point _90 = Point(-qrr[j].y, qrr[j].x); Point _180 = Point(-qrr[j].x, -qrr[j].y); while (q < cnt && (qrr[q + 1] ^ qrr[j]) == 0) ++q; while (s < cnt && (s < q || ((qrr[s + 1] ^ _90) > 0 && (qrr[s + 1] ^ qrr[j]) <= 0))) ++s; while (t < cnt && (t < s || ((qrr[t + 1] ^ _180) > 0 && (qrr[t + 1] ^ _90) <= 0))) ++t; res1 = (res1 + (sumy[s] - sumy[q] + mod) % mod * (qrr[j].x % mod) % mod - (sumx[s] - sumx[q] + mod) % mod * (qrr[j].y) % mod + mod) % mod; res2 = (res2 + (sumy[t] - sumy[s] + mod) % mod * (qrr[j].x % mod) % mod - (sumx[t] - sumx[s] + mod) % mod * (qrr[j].y) % mod + mod) % mod; } } return ((res1 - res2 * 2 % mod + mod) % mod * qpow(3, mod - 2) % mod) % mod; }
voidRUN(){ int T; read(T); while (T--) { read(n); for (int i = 1; i <= n; ++i) { read(p[i].x), read(p[i].y); } ll res = gao(); printf("%lld\n", res); } }