이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 3007;
const ll inf = 2e9;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-6;
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;
vector <int> adj[M];
vector < pair <int,int> > edges;
int n, p[M], sz[M], a[M][M], col[M], cur;
bool vist[M];
int root(int x){
while(x != p[x]){
p[x] = p[p[x]];
x = p[x];
}
return x;
}
void connect(int x, int y){
x = root(x); y = root(y);
if(x == y) return;
if(sz[x] > sz[y]) swap(x, y);
p[x] = y;
sz[y] += sz[x];
adj[x].pb(y); adj[y].pb(x);
edges.pb({x, y});
return;
}
bool check(int node, int p, int src1, int src2){
if(a[node][src1] == a[node][src2]){
col[src1] = col[node];
return 1;
}
bool ret = 0;
for(auto i : adj[node]) if(i != p && vist[i]) ret |= check(i, node, src1, src2);
return ret;
}
void dfs(int node, int p){
vist[node] = 1;
if(node == 1 || !check(p, node, node, p)) col[node] = ++cur;
for(auto i : adj[node]) if(i != p) dfs(i, node);
return;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> n;
for(int i = 1; i <= n; ++i) p[i] = i, sz[i] = 1;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
cin >> a[i][j];
for(int val = 1; val <= 2; ++val)
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
if(a[i][j] == val) connect(i, j);
dfs(1, 0);
for(int i = 1; i <= n; ++i) cout << col[i] << " "; cout << endl;
for(auto i : edges) cout << i.F << " " << i.S << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
izlet.cpp: In function 'int main()':
izlet.cpp:80:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
80 | for(int i = 1; i <= n; ++i) cout << col[i] << " "; cout << endl;
| ^~~
izlet.cpp:80:56: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
80 | for(int i = 1; i <= n; ++i) cout << col[i] << " "; cout << endl;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |