#include "simurgh.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i,n)for (int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define _1 first
#define _2 second
#define INF 1145141919
typedef pair<int, int> P;
vector<int> R[500];
struct UF {
int U[500];
int find(int x){
if(U[x]==x)return x;
return U[x]=find(U[x]);
}
void unite(int x, int y) {
x=find(x), y=find(y);
if(x==y)return;
U[x]=y;
}
bool same(int x, int y) { return find(x)==find(y);}
};
int M;
bool G[500][500];
int ID[500][500];
int ret[500][500];
vector<int> find_roads(int N, vector<int> U, vector<int> V) {
M = U.size();
rep(i, M) G[U[i]][V[i]] = G[V[i]][U[i]] = true;
rep(i, M) ID[U[i]][V[i]] = ID[V[i]][U[i]] = i;
rep(i, N) rep(j, N) ret[i][j] = -1;
UF uf;
rep(x, N) {
rep(i, N) uf.U[i] = i, R[i].clear();
vector<int> cand;
vector<int> def;
rep(i, M) {
if (V[i] == x) swap(U[i], V[i]);
if (U[i] == x) cand.pb(V[i]);
else {
if (!uf.same(U[i], V[i])) {
uf.unite(U[i], V[i]);
def.pb(i);
}
}
}
//cout<<"x="<<x<<": def.size()="<<def.size()<<"\n";
//cout<<"cand={";for (int t:cand)cout<<t<<",";cout<<"}\n";
for (int t : cand) if (ret[x][t] != -1) R[uf.find(t)].pb(t);
for (int t : cand) if (ret[x][t] == -1) R[uf.find(t)].pb(t);
vector<int> rdef(def);
rep(i, N) if (!R[i].empty()) rdef.pb(ID[x][R[i][0]]);
assert(rdef.size()==N-1);
int cr = count_common_roads(rdef);
//cout<<"cr="<<cr<<"\n";
rep(i, N) if (!R[i].empty()) {
if (R[i].size() == 1) {
int t = R[i][0];
assert(ret[x][t] != 0);
ret[x][t] = ret[t][x] = 1;
continue;
}
vector<int> r(def);
rep(other, N) if (i!=other &&!R[other].empty()) r.pb(ID[x][R[other][0]]);
r.pb(-1);
int moto = R[i][0];
int max_r = cr;
vector<P> ps;
ps.pb(P(moto, cr));
for (int j=1; j<R[i].size(); j++) {
int t = R[i][j];
if (ret[x][t] != -1) {
assert(ret[x][moto] != -1);
max_r = max(max_r, cr-ret[x][moto]+ret[x][t]);
}
else {
r.pop_back();
r.pb(ID[x][t]);
assert(r.size()==N-1);
int res = count_common_roads(r);
max_r = max(max_r, res);
ps.pb(P(t, res));
}
}
for (P p : ps) {
int t = p._1, c = p._2;
if (c == max_r) {
//cout<<x<<"<->"<<t<<": yes\n";
// 1
ret[x][t] = ret[t][x] = 1;
}
else {
// 0
ret[x][t] = ret[t][x] = 0;
}
}
}
}
vector<int> r;
rep(i, N) rep(j, i) if (ret[i][j]==1) r.pb(ID[i][j]);
assert(r.size() == N-1);
//assert(count_common_roads(r) == N-1);
return r;
}
Compilation message
In file included from /usr/include/c++/7/cassert:44:0,
from simurgh.cpp:7:
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:69:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
assert(rdef.size()==N-1);
~~~~~~~~~~~^~~~~
simurgh.cpp:87:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=1; j<R[i].size(); j++) {
~^~~~~~~~~~~~
In file included from /usr/include/c++/7/cassert:44:0,
from simurgh.cpp:7:
simurgh.cpp:96:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
assert(r.size()==N-1);
~~~~~~~~^~~~~
simurgh.cpp:119:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
assert(r.size() == N-1);
~~~~~~~~~^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
correct |
2 |
Correct |
2 ms |
464 KB |
correct |
3 |
Correct |
4 ms |
540 KB |
correct |
4 |
Correct |
3 ms |
636 KB |
correct |
5 |
Correct |
3 ms |
636 KB |
correct |
6 |
Correct |
3 ms |
636 KB |
correct |
7 |
Correct |
2 ms |
636 KB |
correct |
8 |
Correct |
2 ms |
636 KB |
correct |
9 |
Correct |
3 ms |
636 KB |
correct |
10 |
Correct |
2 ms |
636 KB |
correct |
11 |
Correct |
2 ms |
636 KB |
correct |
12 |
Correct |
2 ms |
636 KB |
correct |
13 |
Correct |
3 ms |
636 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
correct |
2 |
Correct |
2 ms |
464 KB |
correct |
3 |
Correct |
4 ms |
540 KB |
correct |
4 |
Correct |
3 ms |
636 KB |
correct |
5 |
Correct |
3 ms |
636 KB |
correct |
6 |
Correct |
3 ms |
636 KB |
correct |
7 |
Correct |
2 ms |
636 KB |
correct |
8 |
Correct |
2 ms |
636 KB |
correct |
9 |
Correct |
3 ms |
636 KB |
correct |
10 |
Correct |
2 ms |
636 KB |
correct |
11 |
Correct |
2 ms |
636 KB |
correct |
12 |
Correct |
2 ms |
636 KB |
correct |
13 |
Correct |
3 ms |
636 KB |
correct |
14 |
Correct |
4 ms |
936 KB |
correct |
15 |
Correct |
4 ms |
936 KB |
correct |
16 |
Correct |
5 ms |
936 KB |
correct |
17 |
Correct |
5 ms |
936 KB |
correct |
18 |
Correct |
3 ms |
936 KB |
correct |
19 |
Correct |
6 ms |
1108 KB |
correct |
20 |
Correct |
5 ms |
1108 KB |
correct |
21 |
Correct |
5 ms |
1108 KB |
correct |
22 |
Correct |
4 ms |
1108 KB |
correct |
23 |
Correct |
4 ms |
1108 KB |
correct |
24 |
Correct |
4 ms |
1108 KB |
correct |
25 |
Correct |
3 ms |
1108 KB |
correct |
26 |
Correct |
5 ms |
1108 KB |
correct |
27 |
Correct |
5 ms |
1108 KB |
correct |
28 |
Correct |
3 ms |
1108 KB |
correct |
29 |
Correct |
4 ms |
1108 KB |
correct |
30 |
Correct |
4 ms |
1108 KB |
correct |
31 |
Correct |
5 ms |
1108 KB |
correct |
32 |
Correct |
4 ms |
1108 KB |
correct |
33 |
Correct |
4 ms |
1108 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
correct |
2 |
Correct |
2 ms |
464 KB |
correct |
3 |
Correct |
4 ms |
540 KB |
correct |
4 |
Correct |
3 ms |
636 KB |
correct |
5 |
Correct |
3 ms |
636 KB |
correct |
6 |
Correct |
3 ms |
636 KB |
correct |
7 |
Correct |
2 ms |
636 KB |
correct |
8 |
Correct |
2 ms |
636 KB |
correct |
9 |
Correct |
3 ms |
636 KB |
correct |
10 |
Correct |
2 ms |
636 KB |
correct |
11 |
Correct |
2 ms |
636 KB |
correct |
12 |
Correct |
2 ms |
636 KB |
correct |
13 |
Correct |
3 ms |
636 KB |
correct |
14 |
Correct |
4 ms |
936 KB |
correct |
15 |
Correct |
4 ms |
936 KB |
correct |
16 |
Correct |
5 ms |
936 KB |
correct |
17 |
Correct |
5 ms |
936 KB |
correct |
18 |
Correct |
3 ms |
936 KB |
correct |
19 |
Correct |
6 ms |
1108 KB |
correct |
20 |
Correct |
5 ms |
1108 KB |
correct |
21 |
Correct |
5 ms |
1108 KB |
correct |
22 |
Correct |
4 ms |
1108 KB |
correct |
23 |
Correct |
4 ms |
1108 KB |
correct |
24 |
Correct |
4 ms |
1108 KB |
correct |
25 |
Correct |
3 ms |
1108 KB |
correct |
26 |
Correct |
5 ms |
1108 KB |
correct |
27 |
Correct |
5 ms |
1108 KB |
correct |
28 |
Correct |
3 ms |
1108 KB |
correct |
29 |
Correct |
4 ms |
1108 KB |
correct |
30 |
Correct |
4 ms |
1108 KB |
correct |
31 |
Correct |
5 ms |
1108 KB |
correct |
32 |
Correct |
4 ms |
1108 KB |
correct |
33 |
Correct |
4 ms |
1108 KB |
correct |
34 |
Correct |
182 ms |
2636 KB |
correct |
35 |
Correct |
169 ms |
2764 KB |
correct |
36 |
Correct |
131 ms |
2764 KB |
correct |
37 |
Correct |
16 ms |
2764 KB |
correct |
38 |
Correct |
181 ms |
3236 KB |
correct |
39 |
Correct |
150 ms |
3236 KB |
correct |
40 |
Correct |
126 ms |
3368 KB |
correct |
41 |
Correct |
181 ms |
3672 KB |
correct |
42 |
Correct |
192 ms |
3880 KB |
correct |
43 |
Correct |
132 ms |
3888 KB |
correct |
44 |
Correct |
94 ms |
3888 KB |
correct |
45 |
Correct |
112 ms |
3888 KB |
correct |
46 |
Correct |
80 ms |
3928 KB |
correct |
47 |
Correct |
39 ms |
3928 KB |
correct |
48 |
Correct |
10 ms |
3928 KB |
correct |
49 |
Correct |
15 ms |
3928 KB |
correct |
50 |
Correct |
35 ms |
3940 KB |
correct |
51 |
Correct |
95 ms |
4208 KB |
correct |
52 |
Correct |
78 ms |
4264 KB |
correct |
53 |
Correct |
69 ms |
4280 KB |
correct |
54 |
Correct |
94 ms |
4484 KB |
correct |
55 |
Correct |
84 ms |
4592 KB |
correct |
56 |
Correct |
86 ms |
4696 KB |
correct |
57 |
Correct |
85 ms |
4696 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4696 KB |
correct |
2 |
Correct |
2 ms |
4696 KB |
correct |
3 |
Incorrect |
139 ms |
6568 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
correct |
2 |
Correct |
2 ms |
464 KB |
correct |
3 |
Correct |
4 ms |
540 KB |
correct |
4 |
Correct |
3 ms |
636 KB |
correct |
5 |
Correct |
3 ms |
636 KB |
correct |
6 |
Correct |
3 ms |
636 KB |
correct |
7 |
Correct |
2 ms |
636 KB |
correct |
8 |
Correct |
2 ms |
636 KB |
correct |
9 |
Correct |
3 ms |
636 KB |
correct |
10 |
Correct |
2 ms |
636 KB |
correct |
11 |
Correct |
2 ms |
636 KB |
correct |
12 |
Correct |
2 ms |
636 KB |
correct |
13 |
Correct |
3 ms |
636 KB |
correct |
14 |
Correct |
4 ms |
936 KB |
correct |
15 |
Correct |
4 ms |
936 KB |
correct |
16 |
Correct |
5 ms |
936 KB |
correct |
17 |
Correct |
5 ms |
936 KB |
correct |
18 |
Correct |
3 ms |
936 KB |
correct |
19 |
Correct |
6 ms |
1108 KB |
correct |
20 |
Correct |
5 ms |
1108 KB |
correct |
21 |
Correct |
5 ms |
1108 KB |
correct |
22 |
Correct |
4 ms |
1108 KB |
correct |
23 |
Correct |
4 ms |
1108 KB |
correct |
24 |
Correct |
4 ms |
1108 KB |
correct |
25 |
Correct |
3 ms |
1108 KB |
correct |
26 |
Correct |
5 ms |
1108 KB |
correct |
27 |
Correct |
5 ms |
1108 KB |
correct |
28 |
Correct |
3 ms |
1108 KB |
correct |
29 |
Correct |
4 ms |
1108 KB |
correct |
30 |
Correct |
4 ms |
1108 KB |
correct |
31 |
Correct |
5 ms |
1108 KB |
correct |
32 |
Correct |
4 ms |
1108 KB |
correct |
33 |
Correct |
4 ms |
1108 KB |
correct |
34 |
Correct |
182 ms |
2636 KB |
correct |
35 |
Correct |
169 ms |
2764 KB |
correct |
36 |
Correct |
131 ms |
2764 KB |
correct |
37 |
Correct |
16 ms |
2764 KB |
correct |
38 |
Correct |
181 ms |
3236 KB |
correct |
39 |
Correct |
150 ms |
3236 KB |
correct |
40 |
Correct |
126 ms |
3368 KB |
correct |
41 |
Correct |
181 ms |
3672 KB |
correct |
42 |
Correct |
192 ms |
3880 KB |
correct |
43 |
Correct |
132 ms |
3888 KB |
correct |
44 |
Correct |
94 ms |
3888 KB |
correct |
45 |
Correct |
112 ms |
3888 KB |
correct |
46 |
Correct |
80 ms |
3928 KB |
correct |
47 |
Correct |
39 ms |
3928 KB |
correct |
48 |
Correct |
10 ms |
3928 KB |
correct |
49 |
Correct |
15 ms |
3928 KB |
correct |
50 |
Correct |
35 ms |
3940 KB |
correct |
51 |
Correct |
95 ms |
4208 KB |
correct |
52 |
Correct |
78 ms |
4264 KB |
correct |
53 |
Correct |
69 ms |
4280 KB |
correct |
54 |
Correct |
94 ms |
4484 KB |
correct |
55 |
Correct |
84 ms |
4592 KB |
correct |
56 |
Correct |
86 ms |
4696 KB |
correct |
57 |
Correct |
85 ms |
4696 KB |
correct |
58 |
Correct |
3 ms |
4696 KB |
correct |
59 |
Correct |
2 ms |
4696 KB |
correct |
60 |
Incorrect |
139 ms |
6568 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |