Submission #1243822
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
class uftree
{
public:
int size;
vector<int> par, rank, count;
uftree(int n) : size(n), par(n), rank(n), count(n) {
for (int i = 0; i < size; i++) {
par[i] = i;
rank[i] = 0;
count[i] = 1;
}
}
int number(int x) {
return count[find(x)];
}
int find(int x) {
if (par[x] == x) {
return x;
} else {
return par[x] = find(par[x]);
}
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
return ;
}
if (rank[x] < rank[y]) {
par[x] = y;
} else {
par[y] = x;
if (rank[x] == rank[y]) {
rank[x]++;
}
}
int tmp = count[x] + count[y];
count[x] = count[y] = tmp;
}
bool same(int x, int y) {
return find(x) == find(y);
}
};
signed main()
{
int2(n, m);
vector<pair<int, i_i> > g(m);
rep(i, m) {
int2(a, b); Int(tmp);
g[i].first = tmp;
g[i].second = i_i(a-1, b-1);
}
sort(all(g));
reverse(all(g));
Int(q);
vector<pair<i_i, int> > data(q);
rep(i, q) {
int2(a, b);
data[i].first = i_i(b, a-1);
data[i].second = i;
}
sort(all(data));
reverse(all(data));
int pt = 0;
uftree uf(n);
vi ans(q, 0);
rep(i, q) {
while (pt < n && g[pt].first > data[i].first.first) {
uf.unite(g[pt].second.first, g[pt].second.second);
pt++;
}
ans[data[i].second] = uf.number(data[i].first.second);
}
for (int i : ans) {
cout << i << endl;
}
return 0;
}
Submission Info
Submission Time |
|
Task |
D - 道路の老朽化対策について |
User |
Ti11192916 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2684 Byte |
Status |
WA |
Exec Time |
259 ms |
Memory |
12416 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:23:56: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
^
./Main.cpp:77:5: note: in expansion of macro ‘int2’
int2(n, m);
^
./Main.cpp:23:56: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
^
./Main.cpp:80:9: note: in expansion of macro ‘int2’
int2(a, b); Int(tmp);
^
./Main.cpp:22:40: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
#define Int(x) int x; scanf("%lld", &x);
^
./Main.cpp:80:21: note: in expansion of macro ‘Int’
in...
Judge Result
Set Name |
Sample |
Subtask1 |
All |
Score / Max Score |
0 / 0 |
0 / 50 |
0 / 50 |
Status |
|
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
Subtask1 |
sample_01.txt, sample_02.txt, sample_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt |
All |
sample_01.txt, sample_02.txt, sample_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt |
Case Name |
Status |
Exec Time |
Memory |
sample_01.txt |
AC |
1 ms |
256 KB |
sample_02.txt |
AC |
1 ms |
256 KB |
sample_03.txt |
AC |
1 ms |
256 KB |
subtask1_01.txt |
WA |
4 ms |
384 KB |
subtask1_02.txt |
WA |
4 ms |
384 KB |
subtask1_03.txt |
WA |
4 ms |
384 KB |
subtask1_04.txt |
WA |
3 ms |
256 KB |
subtask1_05.txt |
WA |
4 ms |
384 KB |
subtask1_06.txt |
WA |
4 ms |
384 KB |
subtask1_07.txt |
WA |
5 ms |
384 KB |
subtask2_01.txt |
WA |
255 ms |
10752 KB |
subtask2_02.txt |
WA |
258 ms |
10880 KB |
subtask2_03.txt |
WA |
257 ms |
10752 KB |
subtask2_04.txt |
WA |
257 ms |
10752 KB |
subtask2_05.txt |
WA |
203 ms |
7424 KB |
subtask2_06.txt |
WA |
250 ms |
11008 KB |
subtask2_07.txt |
WA |
251 ms |
11008 KB |
subtask2_08.txt |
WA |
252 ms |
11008 KB |
subtask2_09.txt |
WA |
258 ms |
10752 KB |
subtask2_10.txt |
WA |
258 ms |
10752 KB |
subtask2_11.txt |
WA |
259 ms |
10752 KB |
subtask2_12.txt |
WA |
252 ms |
12416 KB |