mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-14 17:38:48 +00:00
Compare commits
No commits in common. "50abfb0abc0f893b4a1afa701a307bb42f0a2829" and "2fcc1f4f1046d35f4a83db6ad9bb753fdb5c3b22" have entirely different histories.
50abfb0abc
...
2fcc1f4f10
@ -1,71 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <chrono>
|
|
||||||
#include <map>
|
|
||||||
#include <random>
|
|
||||||
#include <set>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using std::cin;
|
|
||||||
using std::cout;
|
|
||||||
const char endl = '\n';
|
|
||||||
|
|
||||||
const int N = 1e6 + 5;
|
|
||||||
|
|
||||||
int n, m, a, b, ans;
|
|
||||||
unsigned long long sum[N];
|
|
||||||
std::vector<std::pair<int, unsigned long long>> g[N];
|
|
||||||
std::map<int, unsigned long long> map;
|
|
||||||
std::set<unsigned long long> set;
|
|
||||||
|
|
||||||
void dfs(int u, int f, unsigned long long s) {
|
|
||||||
sum[u] = sum[f] ^ s;
|
|
||||||
|
|
||||||
for (auto e : g[u]) {
|
|
||||||
int v = e.first;
|
|
||||||
unsigned long long w = e.second;
|
|
||||||
|
|
||||||
if (v == f) continue;
|
|
||||||
|
|
||||||
dfs(v, u, w);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
signed main() {
|
|
||||||
std::ios::sync_with_stdio(false);
|
|
||||||
cin.tie(nullptr);
|
|
||||||
|
|
||||||
std::mt19937_64 rand(std::chrono::system_clock::now().time_since_epoch().count());
|
|
||||||
|
|
||||||
cin >> n >> m;
|
|
||||||
|
|
||||||
for (int i = 1; i < n; i++) {
|
|
||||||
int u, v, w;
|
|
||||||
|
|
||||||
cin >> u >> v >> w;
|
|
||||||
|
|
||||||
if (!map.count(w)) map[w] = rand();
|
|
||||||
set.insert(map[w]);
|
|
||||||
g[u].emplace_back(v, map[w]);
|
|
||||||
g[v].emplace_back(u, map[w]);
|
|
||||||
}
|
|
||||||
|
|
||||||
dfs(1, 0, 0);
|
|
||||||
|
|
||||||
cin >> a >> b;
|
|
||||||
|
|
||||||
while (m--) {
|
|
||||||
int x = a % n + 1,
|
|
||||||
y = b % n + 1;
|
|
||||||
|
|
||||||
unsigned long long s = sum[x] ^ sum[y];
|
|
||||||
|
|
||||||
if (s == 0 || set.count(s)) ans++;
|
|
||||||
|
|
||||||
a = static_cast<long long>(a) * 666073 % 1000000007;
|
|
||||||
b = static_cast<long long>(b) * 233 % 998244353;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << ans << endl;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
BIN
S2OJ/1497/data/data1.in
(Stored with Git LFS)
BIN
S2OJ/1497/data/data1.in
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1497/data/data1.out
(Stored with Git LFS)
BIN
S2OJ/1497/data/data1.out
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1497/data/data2.in
(Stored with Git LFS)
BIN
S2OJ/1497/data/data2.in
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1497/data/data2.out
(Stored with Git LFS)
BIN
S2OJ/1497/data/data2.out
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1497/data/data3.in
(Stored with Git LFS)
BIN
S2OJ/1497/data/data3.in
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1497/data/data3.out
(Stored with Git LFS)
BIN
S2OJ/1497/data/data3.out
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1497/data/data4.in
(Stored with Git LFS)
BIN
S2OJ/1497/data/data4.in
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1497/data/data4.out
(Stored with Git LFS)
BIN
S2OJ/1497/data/data4.out
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1497/data/data5.in
(Stored with Git LFS)
BIN
S2OJ/1497/data/data5.in
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1497/data/data5.out
(Stored with Git LFS)
BIN
S2OJ/1497/data/data5.out
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1497/data/data6.in
(Stored with Git LFS)
BIN
S2OJ/1497/data/data6.in
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1497/data/data6.out
(Stored with Git LFS)
BIN
S2OJ/1497/data/data6.out
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1497/data/problem.conf
(Stored with Git LFS)
BIN
S2OJ/1497/data/problem.conf
(Stored with Git LFS)
Binary file not shown.
@ -1,90 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <cstring>
|
|
||||||
#include <deque>
|
|
||||||
#include <set>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using std::cin;
|
|
||||||
using std::cout;
|
|
||||||
const char endl = '\n';
|
|
||||||
|
|
||||||
const int N = 1000005;
|
|
||||||
|
|
||||||
int n, m, id[N], last[N], dist[N];
|
|
||||||
bool vis[N];
|
|
||||||
std::set<int> cs;
|
|
||||||
std::vector<std::pair<int, int>> c[N], g[N];
|
|
||||||
|
|
||||||
void bfs() {
|
|
||||||
memset(dist, 0x3f, sizeof(dist));
|
|
||||||
|
|
||||||
std::deque<int> q;
|
|
||||||
|
|
||||||
dist[1] = 0;
|
|
||||||
q.emplace_back(1);
|
|
||||||
|
|
||||||
while (!q.empty()) {
|
|
||||||
int u = q.front();
|
|
||||||
q.pop_front();
|
|
||||||
|
|
||||||
if (vis[u]) continue;
|
|
||||||
vis[u] = true;
|
|
||||||
|
|
||||||
for (auto e : g[u]) {
|
|
||||||
int v = e.first,
|
|
||||||
w = e.second;
|
|
||||||
|
|
||||||
if (dist[v] > dist[u] + w) {
|
|
||||||
dist[v] = dist[u] + w;
|
|
||||||
|
|
||||||
if (w) q.emplace_back(v);
|
|
||||||
else q.emplace_front(v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
std::ios::sync_with_stdio(false);
|
|
||||||
cin.tie(nullptr);
|
|
||||||
|
|
||||||
cin >> n >> m;
|
|
||||||
|
|
||||||
for (int i = 1, u, v, c; i <= m; i++) {
|
|
||||||
cin >> u >> v >> c;
|
|
||||||
|
|
||||||
::c[c].emplace_back(u, v);
|
|
||||||
cs.insert(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
int cnt = n;
|
|
||||||
for (int x : cs) {
|
|
||||||
for (auto e : c[x]) {
|
|
||||||
int u = e.first,
|
|
||||||
v = e.second;
|
|
||||||
|
|
||||||
if (last[u] != x) {
|
|
||||||
last[u] = x;
|
|
||||||
id[u] = ++cnt;
|
|
||||||
g[u].emplace_back(id[u], 1);
|
|
||||||
g[id[u]].emplace_back(u, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (last[v] != x) {
|
|
||||||
last[v] = x;
|
|
||||||
id[v] = ++cnt;
|
|
||||||
g[v].emplace_back(id[v], 1);
|
|
||||||
g[id[v]].emplace_back(v, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
g[id[u]].emplace_back(id[v], 0);
|
|
||||||
g[id[v]].emplace_back(id[u], 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bfs();
|
|
||||||
|
|
||||||
cout << (dist[n] == 0x3f3f3f3f ? -1 : dist[n]) << endl;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
BIN
S2OJ/1498/data/data1.in
(Stored with Git LFS)
BIN
S2OJ/1498/data/data1.in
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/data1.out
(Stored with Git LFS)
BIN
S2OJ/1498/data/data1.out
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/data10.in
(Stored with Git LFS)
BIN
S2OJ/1498/data/data10.in
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/data10.out
(Stored with Git LFS)
BIN
S2OJ/1498/data/data10.out
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/data2.in
(Stored with Git LFS)
BIN
S2OJ/1498/data/data2.in
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/data2.out
(Stored with Git LFS)
BIN
S2OJ/1498/data/data2.out
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/data3.in
(Stored with Git LFS)
BIN
S2OJ/1498/data/data3.in
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/data3.out
(Stored with Git LFS)
BIN
S2OJ/1498/data/data3.out
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/data4.in
(Stored with Git LFS)
BIN
S2OJ/1498/data/data4.in
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/data4.out
(Stored with Git LFS)
BIN
S2OJ/1498/data/data4.out
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/data5.in
(Stored with Git LFS)
BIN
S2OJ/1498/data/data5.in
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/data5.out
(Stored with Git LFS)
BIN
S2OJ/1498/data/data5.out
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/data6.in
(Stored with Git LFS)
BIN
S2OJ/1498/data/data6.in
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/data6.out
(Stored with Git LFS)
BIN
S2OJ/1498/data/data6.out
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/data7.in
(Stored with Git LFS)
BIN
S2OJ/1498/data/data7.in
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/data7.out
(Stored with Git LFS)
BIN
S2OJ/1498/data/data7.out
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/data8.in
(Stored with Git LFS)
BIN
S2OJ/1498/data/data8.in
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/data8.out
(Stored with Git LFS)
BIN
S2OJ/1498/data/data8.out
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/data9.in
(Stored with Git LFS)
BIN
S2OJ/1498/data/data9.in
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/data9.out
(Stored with Git LFS)
BIN
S2OJ/1498/data/data9.out
(Stored with Git LFS)
Binary file not shown.
BIN
S2OJ/1498/data/problem.conf
(Stored with Git LFS)
BIN
S2OJ/1498/data/problem.conf
(Stored with Git LFS)
Binary file not shown.
Loading…
Reference in New Issue
Block a user