# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
637909 | 2022-09-03T14:35:07 Z | Cross_Ratio | Reconstruction Project (JOI22_reconstruction) | C++14 | 5000 ms | 9488 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18; ll A[2005]; ll B[2005]; ll C[2005]; // C[i] <= x < C[i+1], ans = x * A[i] + B[i]; typedef pair<ll, ll> P; ll dis[505][505]; ll dis2[505][505]; struct UnionFind { vector<int> root; UnionFind(int n) { root.resize(n); fill(root.begin(),root.end(),-1); } int Find(int n) { if(root[n]<0) return n; int r = Find(root[n]); root[n] = r; return r; } void Merge(int x, int y) { x = Find(x), y = Find(y); if(x==y) return; if(root[x]>root[y]) swap(x, y); root[x] += root[y]; root[y] = x; } }; vector<array<ll, 4>> Tree[2005]; vector<set<array<ll, 4>>> adj; array<ll, 4> Edge[100005]; bool S[100005]; void dfs(int c, int p, int rt) { for(auto n2 : adj[c]) { if(n2[0]==p) continue; dis[rt][n2[0]] = dis[rt][c]; dis2[rt][n2[0]] = dis2[rt][c]; if(dis[rt][n2[0]] > n2[1]) { dis[rt][n2[0]] = n2[1]; dis2[rt][n2[0]] = n2[2]; } dfs(n2[0], c, rt); } } signed main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); int N, M; cin >> N >> M; clock_t st = clock(); adj.resize(N); int i, j; for(i=0;i<M;i++) { int a, b, c; cin >> a>>b>>c; //a = rand() % N + 1; //b = rand() % N+ 1; //c = rand(); Edge[i] = {c, a-1, b-1, i}; } sort(Edge, Edge+M); int Q; cin >> Q; while(Q--) { ll x; ll ans = 0; cin >> x; vector<array<int, 4>> Edge2; for(i=0;i<M;i++) Edge2.push_back({abs(Edge[i][0]-x), Edge[i][1], Edge[i][2], Edge[i][3]}); sort(Edge2.begin(), Edge2.end()); UnionFind UF(N); for(i=0;i<M;i++) { if(UF.Find(Edge2[i][1])==UF.Find(Edge2[i][2])) continue; UF.Merge(Edge2[i][1], Edge2[i][2]); ans += Edge2[i][0]; } cout << ans << '\n'; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 356 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 0 ms | 340 KB | Output is correct |
17 | Correct | 0 ms | 340 KB | Output is correct |
18 | Correct | 0 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 356 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 0 ms | 340 KB | Output is correct |
17 | Correct | 0 ms | 340 KB | Output is correct |
18 | Correct | 0 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 110 ms | 7148 KB | Output is correct |
21 | Correct | 109 ms | 8916 KB | Output is correct |
22 | Correct | 122 ms | 8872 KB | Output is correct |
23 | Correct | 108 ms | 8876 KB | Output is correct |
24 | Correct | 108 ms | 8872 KB | Output is correct |
25 | Correct | 113 ms | 8884 KB | Output is correct |
26 | Correct | 122 ms | 8864 KB | Output is correct |
27 | Correct | 116 ms | 8880 KB | Output is correct |
28 | Correct | 132 ms | 8868 KB | Output is correct |
29 | Correct | 138 ms | 8876 KB | Output is correct |
30 | Correct | 111 ms | 8868 KB | Output is correct |
31 | Correct | 136 ms | 8880 KB | Output is correct |
32 | Correct | 117 ms | 8864 KB | Output is correct |
33 | Correct | 126 ms | 8876 KB | Output is correct |
34 | Correct | 126 ms | 8988 KB | Output is correct |
35 | Correct | 160 ms | 8876 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Execution timed out | 5058 ms | 7516 KB | Time limit exceeded |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 356 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 0 ms | 340 KB | Output is correct |
17 | Correct | 0 ms | 340 KB | Output is correct |
18 | Correct | 0 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Execution timed out | 5044 ms | 2668 KB | Time limit exceeded |
21 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 356 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 0 ms | 340 KB | Output is correct |
17 | Correct | 0 ms | 340 KB | Output is correct |
18 | Correct | 0 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 110 ms | 7148 KB | Output is correct |
21 | Correct | 109 ms | 8916 KB | Output is correct |
22 | Correct | 122 ms | 8872 KB | Output is correct |
23 | Correct | 108 ms | 8876 KB | Output is correct |
24 | Correct | 108 ms | 8872 KB | Output is correct |
25 | Correct | 113 ms | 8884 KB | Output is correct |
26 | Correct | 122 ms | 8864 KB | Output is correct |
27 | Correct | 116 ms | 8880 KB | Output is correct |
28 | Correct | 132 ms | 8868 KB | Output is correct |
29 | Correct | 138 ms | 8876 KB | Output is correct |
30 | Correct | 111 ms | 8868 KB | Output is correct |
31 | Correct | 136 ms | 8880 KB | Output is correct |
32 | Correct | 117 ms | 8864 KB | Output is correct |
33 | Correct | 126 ms | 8876 KB | Output is correct |
34 | Correct | 126 ms | 8988 KB | Output is correct |
35 | Correct | 160 ms | 8876 KB | Output is correct |
36 | Execution timed out | 5052 ms | 9488 KB | Time limit exceeded |
37 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 356 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 340 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 340 KB | Output is correct |
14 | Correct | 0 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 0 ms | 340 KB | Output is correct |
17 | Correct | 0 ms | 340 KB | Output is correct |
18 | Correct | 0 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 110 ms | 7148 KB | Output is correct |
21 | Correct | 109 ms | 8916 KB | Output is correct |
22 | Correct | 122 ms | 8872 KB | Output is correct |
23 | Correct | 108 ms | 8876 KB | Output is correct |
24 | Correct | 108 ms | 8872 KB | Output is correct |
25 | Correct | 113 ms | 8884 KB | Output is correct |
26 | Correct | 122 ms | 8864 KB | Output is correct |
27 | Correct | 116 ms | 8880 KB | Output is correct |
28 | Correct | 132 ms | 8868 KB | Output is correct |
29 | Correct | 138 ms | 8876 KB | Output is correct |
30 | Correct | 111 ms | 8868 KB | Output is correct |
31 | Correct | 136 ms | 8880 KB | Output is correct |
32 | Correct | 117 ms | 8864 KB | Output is correct |
33 | Correct | 126 ms | 8876 KB | Output is correct |
34 | Correct | 126 ms | 8988 KB | Output is correct |
35 | Correct | 160 ms | 8876 KB | Output is correct |
36 | Correct | 0 ms | 340 KB | Output is correct |
37 | Correct | 0 ms | 340 KB | Output is correct |
38 | Correct | 0 ms | 340 KB | Output is correct |
39 | Execution timed out | 5058 ms | 7516 KB | Time limit exceeded |
40 | Halted | 0 ms | 0 KB | - |