QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#265511 | #6503. DFS Order 3 | qwq7 | WA | 82ms | 3488kb | C++20 | 1.0kb | 2023-11-25 18:56:08 | 2023-11-25 18:56:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define endl '\n'
using ll = long long ;
using pii = pair<int,int>;
template<class T>
T lowbit(T x){ return x&-x;}
#define ls u<<1
#define rs u<<1|1
const int mod = 998244353;
const int N = 2e5+10;
const int M = N<<1;
const int P = 1e9+7;
void solve(int id)
{
int n;cin>>n;
vector<int> vis(n+1,0);
vector<pii> ans;
queue<int> q;
vector<vector<int>> adj(n+1,vector<int>(n+1,0));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++) cin>>adj[i][j];
}
q.push(1);
while(!q.empty())
{
int u=q.front();
q.pop();
for(int i=2;i<=n;i++)
{
if(!vis[adj[u][i]])
{
ans.emplace_back(u,adj[u][i]);
break;
}
}
for(int i=n;i>=2;i--)
{
if(!vis[adj[u][i]])
{
q.push(adj[u][i]);
vis[adj[u][i]]=1;
break;
}
}
}
ans.pop_back();
for(auto [x,y]:ans) cout<<x<<' '<<y<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t=1;
cin>>t;
for(int i=1;i<=t;i++) solve(i);
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3424kb
input:
4 2 1 2 2 1 3 1 2 3 2 1 3 3 2 1 4 1 2 3 4 2 1 3 4 3 2 4 1 4 2 1 3 5 1 2 4 3 5 2 4 1 3 5 3 5 1 2 4 4 2 1 3 5 5 3 1 2 4
output:
1 2 1 2 3 2 1 2 4 2 3 2 1 2 5 3 4 2 3 1
result:
ok correct answer! (4 test cases)
Test #2:
score: -100
Wrong Answer
time: 82ms
memory: 3488kb
input:
20000 10 1 2 4 5 6 7 3 8 10 9 2 1 4 5 6 7 3 8 10 9 3 8 1 2 4 5 6 7 10 9 4 5 6 7 1 2 3 8 10 9 5 4 6 7 1 2 3 8 10 9 6 7 4 5 1 2 3 8 10 9 7 6 4 5 1 2 3 8 10 9 8 3 1 2 4 5 6 7 10 9 9 10 1 2 4 5 6 7 3 8 10 1 2 4 5 6 7 3 8 9 10 1 4 3 8 2 9 6 5 7 10 2 8 9 6 3 4 1 5 7 10 3 8 2 9 6 4 1 5 7 10 4 1 3 8 2 9 6 5...
output:
1 2 9 10 8 3 10 1 3 1 7 6 2 1 6 4 1 4 1 4 10 7 6 9 7 5 9 8 5 4 2 8 1 4 8 3 1 9 4 2 7 5 2 8 6 5 8 10 5 9 3 10 1 9 1 6 4 2 9 6 2 10 3 8 10 6 8 7 1 6 5 7 1 9 2 10 8 9 10 3 9 1 6 3 1 5 3 7 5 7 1 10 7 9 2 6 9 8 6 10 4 8 5 10 3 8 1 10 1 10 9 2 1 10 4 8 10 2 8 5 2 3 5 7 3 7 1 4 5 10 8 4 10 9 6 7 9 1 7 4 1 ...
result:
wrong answer your output is not a tree (test case 1)