이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define INF INT_MAX
#define output for(int i=1;i<=N;i++) { for(int j=1;j<=N;j++) { cout << adj[i][j] << " "; }cout<<endl; }cout<<endl;
const int maxN = 2001;
int N, M;
bool adj[maxN][maxN];
vector < vector<int> > res;
vector <int> path;
bool visited[maxN];
int root; bool foundCycle;
void dfs( int p, int x ){
// cout << p << " -> " << x << endl;
if( x == root ){ // cout << "FOUND ROOT" << endl;
foundCycle = true;
adj[x][p] = adj[p][x] = false;
return;
}
if( visited[x] ) return;
visited[x] = true;
for(int j=1;j<=N;j++){ if( j == p || j == x ) continue;
if( !adj[x][j] ) continue;
adj[x][j] = adj[j][x] = false;
dfs( x, j );
if( foundCycle ){
// cout << "FOUND ROOT, DISABLE " << p << "->" << x << " AND " << x << "->" << j << endl;
path.push_back(j); return;
}
adj[x][j] = adj[j][x] = true;
}
}
void printVec( vector <int> v ){
for(int i=0;i<v.size()-1;i++) cout << v[i] << " ";
cout << endl;
}
int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
memset( adj, 0, sizeof adj );
cin >> N >> M;
int x, y;
for(int i=0;i<M;i++){
cin >> x >> y;
adj[x][y] = adj[y][x] = true;
}
for(int i=1;i<=N;i++) for(int j=1;j<=N;j++){
if( !adj[i][j] ) continue;
adj[i][j] = adj[j][i] = false;
memset( visited, 0, sizeof visited );
path.clear(); root = i; foundCycle = false;
dfs( i, j );
path.push_back( j ); path.push_back( i );
if( path.size() == 2 ) continue;
reverse( path.begin(), path.end() );
// printVec( path );
// output;
res.push_back(path);
}
for(int i=0;i<res.size();i++){
printVec( res[i] );
}
}
컴파일 시 표준 에러 (stderr) 메시지
postmen.cpp: In function 'void printVec(std::vector<int>)':
postmen.cpp:45:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v.size()-1;i++) cout << v[i] << " ";
~^~~~~~~~~~~
postmen.cpp: In function 'int main()':
postmen.cpp:79:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<res.size();i++){
~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |